제출 #605356

#제출 시각아이디문제언어결과실행 시간메모리
605356lunchboxFeast (NOI19_feast)C++17
30 / 100
113 ms5708 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 300000;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  static long long pp[N];
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    pp[i] = (i > 0 ? pp[i - 1] : 0) + a;
  }
  function<pair<long long, int>(long long)> solve = [&](long long t) {
    pair<long long, int> last{0, 0}, dp{0, 0};
    for (int i = 0; i < n; i++) {
      dp = max(dp, make_pair(last.first + pp[i] - t, last.second + 1));
      last = max(last, make_pair(dp.first - pp[i], dp.second));
    }
    return dp;
  };
  long long low = -1, hi = 0x3f3f3f3f3f3f3f3f;
  while (low < hi) {
    long long t = (low + hi + 1) / 2;
    if (solve(t).second >= k)
      low = t;
    else
      hi = t - 1;
  }
  printf("%lld\n", solve(low).first + low * k);
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

feast.cpp: In function 'int main()':
feast.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d", &a);
      |     ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...