답안 #605356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605356 2022-07-25T16:18:00 Z lunchbox Feast (NOI19_feast) C++17
30 / 100
113 ms 5708 KB
#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;
}

Compilation message

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);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 5272 KB Output is correct
2 Correct 73 ms 5448 KB Output is correct
3 Correct 63 ms 5584 KB Output is correct
4 Correct 72 ms 5468 KB Output is correct
5 Correct 64 ms 5452 KB Output is correct
6 Correct 67 ms 5440 KB Output is correct
7 Correct 62 ms 5328 KB Output is correct
8 Correct 63 ms 5572 KB Output is correct
9 Correct 64 ms 5324 KB Output is correct
10 Correct 65 ms 5416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 3700 KB Output is correct
2 Correct 54 ms 3756 KB Output is correct
3 Correct 59 ms 3680 KB Output is correct
4 Correct 54 ms 3648 KB Output is correct
5 Correct 87 ms 5360 KB Output is correct
6 Correct 63 ms 3668 KB Output is correct
7 Correct 55 ms 3732 KB Output is correct
8 Correct 72 ms 5484 KB Output is correct
9 Correct 61 ms 5344 KB Output is correct
10 Correct 54 ms 3688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 5512 KB Output is correct
2 Correct 87 ms 5564 KB Output is correct
3 Correct 91 ms 5580 KB Output is correct
4 Correct 87 ms 5556 KB Output is correct
5 Correct 91 ms 5508 KB Output is correct
6 Correct 113 ms 5644 KB Output is correct
7 Correct 87 ms 5660 KB Output is correct
8 Correct 85 ms 5708 KB Output is correct
9 Correct 95 ms 5580 KB Output is correct
10 Correct 91 ms 5608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 5272 KB Output is correct
2 Correct 73 ms 5448 KB Output is correct
3 Correct 63 ms 5584 KB Output is correct
4 Correct 72 ms 5468 KB Output is correct
5 Correct 64 ms 5452 KB Output is correct
6 Correct 67 ms 5440 KB Output is correct
7 Correct 62 ms 5328 KB Output is correct
8 Correct 63 ms 5572 KB Output is correct
9 Correct 64 ms 5324 KB Output is correct
10 Correct 65 ms 5416 KB Output is correct
11 Correct 57 ms 3700 KB Output is correct
12 Correct 54 ms 3756 KB Output is correct
13 Correct 59 ms 3680 KB Output is correct
14 Correct 54 ms 3648 KB Output is correct
15 Correct 87 ms 5360 KB Output is correct
16 Correct 63 ms 3668 KB Output is correct
17 Correct 55 ms 3732 KB Output is correct
18 Correct 72 ms 5484 KB Output is correct
19 Correct 61 ms 5344 KB Output is correct
20 Correct 54 ms 3688 KB Output is correct
21 Correct 89 ms 5512 KB Output is correct
22 Correct 87 ms 5564 KB Output is correct
23 Correct 91 ms 5580 KB Output is correct
24 Correct 87 ms 5556 KB Output is correct
25 Correct 91 ms 5508 KB Output is correct
26 Correct 113 ms 5644 KB Output is correct
27 Correct 87 ms 5660 KB Output is correct
28 Correct 85 ms 5708 KB Output is correct
29 Correct 95 ms 5580 KB Output is correct
30 Correct 91 ms 5608 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Output isn't correct
33 Halted 0 ms 0 KB -