Submission #1017557

# Submission time Handle Problem Language Result Execution time Memory
1017557 2024-07-09T08:49:18 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
957 ms 24024 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
pair<int,int> solve(int l,int a[],int n){
    vector<vector<pair<int,int>>> DP(n,vector<pair<int,int>>(2));
    DP[0][0]={0,0};
    DP[0][1]={a[0]-l,1};
    for(int i=1;i<n;i++){
        DP[i][0]=max(DP[i-1][0],DP[i-1][1]);
        DP[i][1]=max(DP[i-1][1],{DP[i-1][0].first-l,DP[i-1][0].second+1});
        DP[i][1].first+=a[i];
    }
    return max(DP[n-1][0],DP[n-1][1]);
}
signed main() {
    int n,k;
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int low=0,high=1e18;
    while(low<high){
        int mid=(high+low+1)/2;
        if(solve(mid,a,n).second>=k){
            low=mid;
        }
        else{
            high=mid-1;
        }
    }
    cout << solve(low,a,n).first+low*k;
}
# Verdict Execution time Memory Grader output
1 Correct 854 ms 23436 KB Output is correct
2 Correct 828 ms 23632 KB Output is correct
3 Correct 831 ms 23912 KB Output is correct
4 Correct 847 ms 23832 KB Output is correct
5 Correct 768 ms 23620 KB Output is correct
6 Correct 784 ms 23300 KB Output is correct
7 Correct 809 ms 23228 KB Output is correct
8 Correct 847 ms 23808 KB Output is correct
9 Correct 812 ms 23500 KB Output is correct
10 Correct 852 ms 23512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 751 ms 23224 KB Output is correct
2 Correct 804 ms 23976 KB Output is correct
3 Correct 791 ms 23364 KB Output is correct
4 Correct 849 ms 23548 KB Output is correct
5 Correct 791 ms 23260 KB Output is correct
6 Correct 742 ms 23356 KB Output is correct
7 Correct 853 ms 23960 KB Output is correct
8 Correct 812 ms 23900 KB Output is correct
9 Correct 787 ms 23172 KB Output is correct
10 Correct 781 ms 23848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 937 ms 23704 KB Output is correct
2 Correct 892 ms 23464 KB Output is correct
3 Correct 884 ms 23604 KB Output is correct
4 Correct 831 ms 23360 KB Output is correct
5 Correct 871 ms 23612 KB Output is correct
6 Correct 877 ms 24024 KB Output is correct
7 Correct 841 ms 23916 KB Output is correct
8 Correct 922 ms 23696 KB Output is correct
9 Correct 911 ms 23888 KB Output is correct
10 Correct 850 ms 23840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 432 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 432 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 4 ms 444 KB Output is correct
29 Correct 4 ms 584 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 854 ms 23436 KB Output is correct
2 Correct 828 ms 23632 KB Output is correct
3 Correct 831 ms 23912 KB Output is correct
4 Correct 847 ms 23832 KB Output is correct
5 Correct 768 ms 23620 KB Output is correct
6 Correct 784 ms 23300 KB Output is correct
7 Correct 809 ms 23228 KB Output is correct
8 Correct 847 ms 23808 KB Output is correct
9 Correct 812 ms 23500 KB Output is correct
10 Correct 852 ms 23512 KB Output is correct
11 Correct 751 ms 23224 KB Output is correct
12 Correct 804 ms 23976 KB Output is correct
13 Correct 791 ms 23364 KB Output is correct
14 Correct 849 ms 23548 KB Output is correct
15 Correct 791 ms 23260 KB Output is correct
16 Correct 742 ms 23356 KB Output is correct
17 Correct 853 ms 23960 KB Output is correct
18 Correct 812 ms 23900 KB Output is correct
19 Correct 787 ms 23172 KB Output is correct
20 Correct 781 ms 23848 KB Output is correct
21 Correct 937 ms 23704 KB Output is correct
22 Correct 892 ms 23464 KB Output is correct
23 Correct 884 ms 23604 KB Output is correct
24 Correct 831 ms 23360 KB Output is correct
25 Correct 871 ms 23612 KB Output is correct
26 Correct 877 ms 24024 KB Output is correct
27 Correct 841 ms 23916 KB Output is correct
28 Correct 922 ms 23696 KB Output is correct
29 Correct 911 ms 23888 KB Output is correct
30 Correct 850 ms 23840 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 432 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 4 ms 348 KB Output is correct
52 Correct 4 ms 348 KB Output is correct
53 Correct 4 ms 348 KB Output is correct
54 Correct 4 ms 344 KB Output is correct
55 Correct 4 ms 348 KB Output is correct
56 Correct 4 ms 348 KB Output is correct
57 Correct 4 ms 348 KB Output is correct
58 Correct 4 ms 444 KB Output is correct
59 Correct 4 ms 584 KB Output is correct
60 Correct 4 ms 344 KB Output is correct
61 Correct 902 ms 23492 KB Output is correct
62 Correct 879 ms 23932 KB Output is correct
63 Correct 871 ms 23300 KB Output is correct
64 Correct 881 ms 23980 KB Output is correct
65 Correct 957 ms 23952 KB Output is correct
66 Correct 923 ms 23932 KB Output is correct
67 Correct 895 ms 23372 KB Output is correct
68 Correct 875 ms 23776 KB Output is correct
69 Correct 822 ms 23284 KB Output is correct
70 Correct 884 ms 23384 KB Output is correct