Submission #605372

# Submission time Handle Problem Language Result Execution time Memory
605372 2022-07-25T16:27:59 Z lunchbox Feast (NOI19_feast) C++17
59 / 100
115 ms 2648 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 300000;

pair<long long, int> solve(int n, long long *pp, 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;
}

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;
  }
  long long low = 0, hi = 0x3f3f3f3f3f3f3f3f;
  while (low < hi) {
    long long t = (low + hi) / 2;
    if (solve(n, pp, t).second > k)
      low = t + 1;
    else
      hi = t;
  }
  printf("%lld\n", solve(n, pp, low).first + low * k);
  return 0;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d", &a);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 2556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 2576 KB Output is correct
2 Correct 51 ms 2592 KB Output is correct
3 Correct 75 ms 2464 KB Output is correct
4 Incorrect 49 ms 2516 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 2648 KB Output is correct
2 Correct 91 ms 2616 KB Output is correct
3 Correct 91 ms 2524 KB Output is correct
4 Correct 112 ms 2476 KB Output is correct
5 Correct 88 ms 2600 KB Output is correct
6 Correct 115 ms 2508 KB Output is correct
7 Correct 90 ms 2636 KB Output is correct
8 Correct 86 ms 2592 KB Output is correct
9 Correct 91 ms 2636 KB Output is correct
10 Correct 88 ms 2620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 2 ms 212 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 2556 KB Output isn't correct
2 Halted 0 ms 0 KB -