답안 #789496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789496 2023-07-21T12:49:19 Z Warinchai Feast (NOI19_feast) C++14
100 / 100
103 ms 8056 KB
#include<bits/stdc++.h>
using namespace std;
long long ar[300005];
long long sum[300005];
long long n,k;
pair<long long,int> solve(long long l){
    pair<long long,int>dp={0,0},best={0,0};
    for(int i=1;i<=n;i++){
        dp=max(dp,{sum[i]-l+best.first,best.second-1});
        best=max(best,{dp.first-sum[i],dp.second});
    }
    dp.second*=-1;
    return dp;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    long long sm=0;
    for(int i=1;i<=n;i++){
        cin>>ar[i];
        sm+=ar[i];
        sum[i]=sm;
    }
    long long st=0,en=3e14+1;
    long long ans;
    while(st<=en){
        long long m=(st+en)/2;
        pair<long long,int>tmp=solve(m);
        //cout<<m<<" "<<tmp.first<<" "<<tmp.second<<endl;
        if(tmp.second<=k){
            en=m-1;
            ans=tmp.first+m*k;
        }else{
            st=m+1;
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 4852 KB Output is correct
2 Correct 50 ms 7728 KB Output is correct
3 Correct 41 ms 7848 KB Output is correct
4 Correct 39 ms 7832 KB Output is correct
5 Correct 46 ms 7688 KB Output is correct
6 Correct 40 ms 7664 KB Output is correct
7 Correct 59 ms 7632 KB Output is correct
8 Correct 39 ms 7732 KB Output is correct
9 Correct 45 ms 7628 KB Output is correct
10 Correct 48 ms 7748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 4820 KB Output is correct
2 Correct 39 ms 4900 KB Output is correct
3 Correct 43 ms 4776 KB Output is correct
4 Correct 35 ms 4916 KB Output is correct
5 Correct 50 ms 7656 KB Output is correct
6 Correct 37 ms 5988 KB Output is correct
7 Correct 53 ms 6140 KB Output is correct
8 Correct 50 ms 7756 KB Output is correct
9 Correct 38 ms 7632 KB Output is correct
10 Correct 37 ms 6100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 4872 KB Output is correct
2 Correct 63 ms 4900 KB Output is correct
3 Correct 77 ms 4936 KB Output is correct
4 Correct 63 ms 4900 KB Output is correct
5 Correct 71 ms 4936 KB Output is correct
6 Correct 68 ms 4864 KB Output is correct
7 Correct 72 ms 4984 KB Output is correct
8 Correct 65 ms 4932 KB Output is correct
9 Correct 66 ms 4920 KB Output is correct
10 Correct 69 ms 4980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 4852 KB Output is correct
2 Correct 50 ms 7728 KB Output is correct
3 Correct 41 ms 7848 KB Output is correct
4 Correct 39 ms 7832 KB Output is correct
5 Correct 46 ms 7688 KB Output is correct
6 Correct 40 ms 7664 KB Output is correct
7 Correct 59 ms 7632 KB Output is correct
8 Correct 39 ms 7732 KB Output is correct
9 Correct 45 ms 7628 KB Output is correct
10 Correct 48 ms 7748 KB Output is correct
11 Correct 41 ms 4820 KB Output is correct
12 Correct 39 ms 4900 KB Output is correct
13 Correct 43 ms 4776 KB Output is correct
14 Correct 35 ms 4916 KB Output is correct
15 Correct 50 ms 7656 KB Output is correct
16 Correct 37 ms 5988 KB Output is correct
17 Correct 53 ms 6140 KB Output is correct
18 Correct 50 ms 7756 KB Output is correct
19 Correct 38 ms 7632 KB Output is correct
20 Correct 37 ms 6100 KB Output is correct
21 Correct 67 ms 4872 KB Output is correct
22 Correct 63 ms 4900 KB Output is correct
23 Correct 77 ms 4936 KB Output is correct
24 Correct 63 ms 4900 KB Output is correct
25 Correct 71 ms 4936 KB Output is correct
26 Correct 68 ms 4864 KB Output is correct
27 Correct 72 ms 4984 KB Output is correct
28 Correct 65 ms 4932 KB Output is correct
29 Correct 66 ms 4920 KB Output is correct
30 Correct 69 ms 4980 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 328 KB Output is correct
37 Correct 0 ms 324 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 1 ms 320 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 89 ms 7864 KB Output is correct
62 Correct 90 ms 8056 KB Output is correct
63 Correct 75 ms 7848 KB Output is correct
64 Correct 92 ms 8000 KB Output is correct
65 Correct 95 ms 8000 KB Output is correct
66 Correct 94 ms 7976 KB Output is correct
67 Correct 103 ms 7888 KB Output is correct
68 Correct 69 ms 7908 KB Output is correct
69 Correct 65 ms 7852 KB Output is correct
70 Correct 67 ms 7816 KB Output is correct