Submission #733384

# Submission time Handle Problem Language Result Execution time Memory
733384 2023-04-30T15:49:25 Z finn__ Feast (NOI19_feast) C++17
22 / 100
85 ms 5580 KB
#include <bits/stdc++.h>
using namespace std;

constexpr size_t N = 300000;

int64_t a[N];

pair<int64_t, int64_t> dp(size_t n, int64_t lambda)
{
    int64_t mu = 0, nu = 0, p = 0, cnt = 0, _cnt = 0;
    for (size_t i = 0; i < n; ++i)
    {
        p += a[i];
        if (mu + p - lambda > nu)
            nu = mu + p - lambda, _cnt = cnt + 1;
        if (nu - p > mu)
            cnt = _cnt, mu = nu - p;
    }
    return {nu, cnt};
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    size_t n, k;
    cin >> n >> k;
    for (size_t i = 0; i < n; ++i)
        cin >> a[i];

    int64_t u = 0, v = 1LL << 55;
    while (u < v)
    {
        if (dp(n, (u + v) / 2).second <= k)
            v = (u + v) / 2;
        else
            u = (u + v) / 2 + 1;
    }
    auto const [objective_val, cnt] = dp(n, u);
    cout << objective_val + k * u << '\n';
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:35:39: warning: comparison of integer expressions of different signedness: 'long int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if (dp(n, (u + v) / 2).second <= k)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2516 KB Output is correct
2 Correct 58 ms 5580 KB Output is correct
3 Correct 54 ms 5532 KB Output is correct
4 Correct 56 ms 5492 KB Output is correct
5 Correct 50 ms 5472 KB Output is correct
6 Correct 52 ms 5364 KB Output is correct
7 Correct 52 ms 5380 KB Output is correct
8 Correct 50 ms 5492 KB Output is correct
9 Correct 53 ms 5328 KB Output is correct
10 Correct 49 ms 5416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 2480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 70 ms 2592 KB Output is correct
2 Correct 75 ms 2600 KB Output is correct
3 Correct 76 ms 2504 KB Output is correct
4 Correct 85 ms 2600 KB Output is correct
5 Correct 69 ms 2620 KB Output is correct
6 Correct 73 ms 2636 KB Output is correct
7 Correct 72 ms 2640 KB Output is correct
8 Correct 71 ms 2612 KB Output is correct
9 Correct 72 ms 2636 KB Output is correct
10 Correct 71 ms 2644 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2516 KB Output is correct
2 Correct 58 ms 5580 KB Output is correct
3 Correct 54 ms 5532 KB Output is correct
4 Correct 56 ms 5492 KB Output is correct
5 Correct 50 ms 5472 KB Output is correct
6 Correct 52 ms 5364 KB Output is correct
7 Correct 52 ms 5380 KB Output is correct
8 Correct 50 ms 5492 KB Output is correct
9 Correct 53 ms 5328 KB Output is correct
10 Correct 49 ms 5416 KB Output is correct
11 Incorrect 40 ms 2480 KB Output isn't correct
12 Halted 0 ms 0 KB -