(200815) 코드포스

Codeforces materials usage license (v. 0.1) 에 따라 codeforces.com 의 문제임을 알립니다.

Original problem link: Problem - 1394A - Codeforces
Difficulty: 1800



Example

Input

5 2 11
8 10 15 23 5

Output

48

Input

20 2 16
20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7

Output

195


Common codes for Codeforces
#include <algorithm>
#include <array>
#include <cmath>
#include <functional> 
#include <iostream>
#include <memory>
#include <queue>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>

namespace predefined {

#ifdef CODEFORCES_DEBUG
  constexpr bool kIsDebug = true;
#else
  constexpr bool kIsDebug = false;
#endif

enum class LogType {
  INFO,
  DEBUG
};

template <LogType Type, bool... Bools>
struct Log;

template <>
struct Log<LogType::INFO> {
  Log() {}
  ~Log() { std::cout << '\n'; }

  template <typename T>
  Log& operator<< (const T &t) {
    std::cout << t;
    return *this;
  }
};

template <>
struct Log<LogType::DEBUG, true>{
  Log() {}
  ~Log() { std::cout << '\n'; }

  void Open() {
    freopen("input.txt", "r", stdin);
  }

  template <typename T>
  Log& operator<< (const T &t) {
    std::cout << t;
    return *this;
  }
};

template <>
struct Log<LogType::DEBUG, false> {
  Log() {}
  ~Log() {}

  void Open() {}

  template <typename T>
  Log& operator<< (const T &t) { return *this; }
};

namespace solver {

using SolveFunc = std::function<void()>;

template<typename MultiRunner>
void Run(SolveFunc solve_func);

template<>
void Run<std::true_type>(SolveFunc solve_func) {
  int test_case;
  std::cin >> test_case;

  while (test_case--) {
    solve_func();
  }
}

template<>
void Run<std::false_type>(SolveFunc solve_func) {
  solve_func();
}

} // solver

template <bool MultiTest>
struct Solver {
  constexpr static bool condition = MultiTest | kIsDebug;
  typedef typename std::conditional<condition, std::true_type, std::false_type>::type run_type;

  explicit Solver(solver::SolveFunc solve_func) {
    solver::Run<run_type>(solve_func);
  }
};

template<typename T>
struct BoolMap {
  explicit BoolMap(const T &_true_value, const T &_false_value) 
    : true_value(_true_value),
      false_value(_false_value) {}

  const T true_value;
  const T false_value;

  const T inline GetValue(const bool bool_key) const {
    return bool_key ? true_value : false_value;  
  };
};

}  // predefined;

#define LOG_INFO predefined::Log<predefined::LogType::INFO>()
#define LOG_DEBUG predefined::Log<predefined::LogType::DEBUG, predefined::kIsDebug>()
#define LOG(LEVEL) LOG_##LEVEL
#define LABEL(variable_name) #variable_name << ": " << variable_name << " "

#define INIT_ANSWER(type, true_value, false_value) \
  const predefined::BoolMap<type> predefined_bool_map(true_value, false_value)
#define INIT_STRING_ANSWER(true_string, false_string) \
  INIT_ANSWER(std::string, true_string, false_string)
#define GET_ANSWER(bool_key) \
  predefined_bool_map.GetValue(bool_key)

#define INIT_CODEFORCES() \
  std::ios::sync_with_stdio(false); \
  std::cin.tie(NULL); \
  LOG(DEBUG).Open();

내일 좀 더 보면 될꺼 같네요. 오늘은 요까지

1394A 오답
namespace {
using namespace std;

constexpr bool kMultiTestCase = false;
using Solver = predefined::Solver<kMultiTestCase>;

constexpr int64_t kMinusInf = -1e16;
}  // unnamed namespace;

int n, d;
int64_t m;
vector<int64_t> jokes;
vector<int64_t> kiddings;
vector<int64_t> memory;

int64_t Dp(int kidding_cnt) {
  if ((kidding_cnt - 1) * d > n) return kMinusInf;
  
  auto &ret = memory[kidding_cnt];
  if (ret != -1) return ret;
  
  int joke_rest_count = n - (kidding_cnt - 1) * d; 
  int index = min(joke_rest_count > 0 ? joke_rest_count - 1 : 0, static_cast<int>(jokes.size()) - 1);
  ret = jokes[index];
  if (kidding_cnt != kiddings.size()) ret = max(ret, kiddings[kidding_cnt] + Dp(kidding_cnt + 1));
 
  return ret;
}

void solve() {
  cin >> n >> d >> m;

  for (int i = 0; i < n; ++i) {
    int64_t input;
    cin >> input;
    if (input > m) kiddings.push_back(input);
    else jokes.push_back(input);
  }

  sort(jokes.begin(), jokes.end(), greater<int64_t>());
  for (int i = 1; i < jokes.size(); ++i) jokes[i] = jokes[i] + jokes[i - 1];

  sort(kiddings.begin(), kiddings.end(), greater<int64_t>());

  if (kiddings.size() == 0) {
    LOG_INFO << jokes.back();
    return;
  }

  --n;
  ++d;
  memory.resize(kiddings.size() + 1, -1);
  LOG_INFO << kiddings[0] + Dp(1);
}

int main(int argc, char** argv) {
  INIT_CODEFORCES();

  Solver::Run(&solve);

  return 0;
}