Submission #1102898

# Submission time Handle Problem Language Result Execution time Memory
1102898 2024-10-19T08:23:38 Z Tenis0206 Feast (NOI19_feast) C++11
100 / 100
103 ms 12888 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int nmax = 3e5;

int n,k;
int v[nmax + 5], sp[nmax + 5];

pair<int,int> dp[nmax + 5];

pair<int,int> calculate(int c)
{
    pair<int,int> Max = {0, 0};
    dp[0] = {0, 0};
    for(int i=1;i<=n;i++)
    {
        dp[i] = dp[i - 1];
        if(Max.first + sp[i] - c > dp[i].first || (Max.first + sp[i] - c == dp[i].first && Max.second + 1 < dp[i].second))
        {
            dp[i].first = Max.first + sp[i] - c;
            dp[i].second = Max.second + 1;
        }
        if(dp[i].first - sp[i] > Max.first || (dp[i].first - sp[i] == Max.first && dp[i].second < Max.second))
        {
            Max.first = dp[i].first - sp[i];
            Max.second = dp[i].second;
        }
    }
    return dp[n];
}

int solve()
{
    int st = 1;
    int dr = 1e14;
    while(st<=dr)
    {
        int mij = (st + dr) >> 1;
        pair<int,int> val = calculate(mij);
        if(val.second == k)
        {
            return val.first + k * mij;
        }
        if(val.second < k)
        {
            dr = mij - 1;
        }
        else
        {
            st = mij + 1;
        }
    }
    pair<int,int> val = calculate(st);
    return val.first + val.second * st;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        sp[i] = sp[i - 1] + v[i];
    }
    cout<<solve()<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 51 ms 12364 KB Output is correct
2 Correct 42 ms 12372 KB Output is correct
3 Correct 43 ms 12628 KB Output is correct
4 Correct 43 ms 12620 KB Output is correct
5 Correct 42 ms 12520 KB Output is correct
6 Correct 42 ms 12372 KB Output is correct
7 Correct 41 ms 12384 KB Output is correct
8 Correct 42 ms 12640 KB Output is correct
9 Correct 52 ms 12364 KB Output is correct
10 Correct 52 ms 12364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10580 KB Output is correct
2 Correct 23 ms 10836 KB Output is correct
3 Correct 32 ms 10576 KB Output is correct
4 Correct 34 ms 10836 KB Output is correct
5 Correct 22 ms 12372 KB Output is correct
6 Correct 23 ms 10664 KB Output is correct
7 Correct 35 ms 10836 KB Output is correct
8 Correct 24 ms 12628 KB Output is correct
9 Correct 30 ms 12364 KB Output is correct
10 Correct 36 ms 10876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 12600 KB Output is correct
2 Correct 39 ms 12580 KB Output is correct
3 Correct 36 ms 12628 KB Output is correct
4 Correct 40 ms 12436 KB Output is correct
5 Correct 37 ms 12656 KB Output is correct
6 Correct 50 ms 12696 KB Output is correct
7 Correct 44 ms 12884 KB Output is correct
8 Correct 42 ms 12628 KB Output is correct
9 Correct 41 ms 12760 KB Output is correct
10 Correct 38 ms 12884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2388 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2412 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2388 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2412 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 2 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 1 ms 2556 KB Output is correct
14 Correct 1 ms 2388 KB Output is correct
15 Correct 1 ms 2388 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 1 ms 2388 KB Output is correct
19 Correct 1 ms 2388 KB Output is correct
20 Correct 1 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2388 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2412 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 2 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 1 ms 2556 KB Output is correct
14 Correct 1 ms 2388 KB Output is correct
15 Correct 1 ms 2388 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 1 ms 2388 KB Output is correct
19 Correct 1 ms 2388 KB Output is correct
20 Correct 1 ms 2552 KB Output is correct
21 Correct 2 ms 2388 KB Output is correct
22 Correct 2 ms 2388 KB Output is correct
23 Correct 1 ms 2388 KB Output is correct
24 Correct 2 ms 2388 KB Output is correct
25 Correct 2 ms 2388 KB Output is correct
26 Correct 2 ms 2392 KB Output is correct
27 Correct 1 ms 2388 KB Output is correct
28 Correct 1 ms 2400 KB Output is correct
29 Correct 2 ms 2400 KB Output is correct
30 Correct 1 ms 2400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 12364 KB Output is correct
2 Correct 42 ms 12372 KB Output is correct
3 Correct 43 ms 12628 KB Output is correct
4 Correct 43 ms 12620 KB Output is correct
5 Correct 42 ms 12520 KB Output is correct
6 Correct 42 ms 12372 KB Output is correct
7 Correct 41 ms 12384 KB Output is correct
8 Correct 42 ms 12640 KB Output is correct
9 Correct 52 ms 12364 KB Output is correct
10 Correct 52 ms 12364 KB Output is correct
11 Correct 25 ms 10580 KB Output is correct
12 Correct 23 ms 10836 KB Output is correct
13 Correct 32 ms 10576 KB Output is correct
14 Correct 34 ms 10836 KB Output is correct
15 Correct 22 ms 12372 KB Output is correct
16 Correct 23 ms 10664 KB Output is correct
17 Correct 35 ms 10836 KB Output is correct
18 Correct 24 ms 12628 KB Output is correct
19 Correct 30 ms 12364 KB Output is correct
20 Correct 36 ms 10876 KB Output is correct
21 Correct 36 ms 12600 KB Output is correct
22 Correct 39 ms 12580 KB Output is correct
23 Correct 36 ms 12628 KB Output is correct
24 Correct 40 ms 12436 KB Output is correct
25 Correct 37 ms 12656 KB Output is correct
26 Correct 50 ms 12696 KB Output is correct
27 Correct 44 ms 12884 KB Output is correct
28 Correct 42 ms 12628 KB Output is correct
29 Correct 41 ms 12760 KB Output is correct
30 Correct 38 ms 12884 KB Output is correct
31 Correct 2 ms 2388 KB Output is correct
32 Correct 1 ms 2512 KB Output is correct
33 Correct 1 ms 2388 KB Output is correct
34 Correct 1 ms 2388 KB Output is correct
35 Correct 1 ms 2388 KB Output is correct
36 Correct 1 ms 2388 KB Output is correct
37 Correct 1 ms 2388 KB Output is correct
38 Correct 1 ms 2388 KB Output is correct
39 Correct 1 ms 2412 KB Output is correct
40 Correct 1 ms 2388 KB Output is correct
41 Correct 2 ms 2388 KB Output is correct
42 Correct 1 ms 2388 KB Output is correct
43 Correct 1 ms 2556 KB Output is correct
44 Correct 1 ms 2388 KB Output is correct
45 Correct 1 ms 2388 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 1 ms 2388 KB Output is correct
48 Correct 1 ms 2388 KB Output is correct
49 Correct 1 ms 2388 KB Output is correct
50 Correct 1 ms 2552 KB Output is correct
51 Correct 2 ms 2388 KB Output is correct
52 Correct 2 ms 2388 KB Output is correct
53 Correct 1 ms 2388 KB Output is correct
54 Correct 2 ms 2388 KB Output is correct
55 Correct 2 ms 2388 KB Output is correct
56 Correct 2 ms 2392 KB Output is correct
57 Correct 1 ms 2388 KB Output is correct
58 Correct 1 ms 2400 KB Output is correct
59 Correct 2 ms 2400 KB Output is correct
60 Correct 1 ms 2400 KB Output is correct
61 Correct 76 ms 12632 KB Output is correct
62 Correct 103 ms 12888 KB Output is correct
63 Correct 64 ms 12628 KB Output is correct
64 Correct 80 ms 12620 KB Output is correct
65 Correct 69 ms 12620 KB Output is correct
66 Correct 74 ms 12620 KB Output is correct
67 Correct 73 ms 12636 KB Output is correct
68 Correct 57 ms 12620 KB Output is correct
69 Correct 45 ms 12620 KB Output is correct
70 Correct 39 ms 12560 KB Output is correct