Submission #605371

# Submission time Handle Problem Language Result Execution time Memory
605371 2022-07-25T16:27:47 Z lunchbox Feast (NOI19_feast) C++17
0 / 100
65 ms 2596 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 = min(dp, make_pair(last.first + pp[i] - t, last.second + 1));
    last = min(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 58 ms 2556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 2576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 2596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 2556 KB Output isn't correct
2 Halted 0 ms 0 KB -