# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1017473 | 2024-07-09T08:16:37 Z | vjudge1 | Feast (NOI19_feast) | C++14 | 112 ms | 14012 KB |
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define taskname "" using namespace std; ll n,k,i,l,r,mid,answer=-1e18,dp[300009][2],a[300009],cnt[300009][2],sum; pll ans; pll check(ll v){ dp[1][0]=0; dp[1][1]=a[1]-v; cnt[1][0]=0; cnt[1][1]=1; for(i=2;i<=n;i++){ if(dp[i-1][1]<dp[i-1][0]){ dp[i][0]=dp[i-1][0]; cnt[i][0]=cnt[i-1][0]; }else{ dp[i][0]=dp[i-1][1]; cnt[i][0]=cnt[i-1][1]; } if(dp[i-1][1]+a[i]<dp[i-1][0]+a[i]-v){ dp[i][1]=dp[i-1][0]+a[i]-v; cnt[i][1]=cnt[i-1][0]+1; }else{ dp[i][1]=dp[i-1][1]+a[i]; cnt[i][1]=cnt[i-1][1]; } }pll res={dp[n][1],cnt[n][1]}; pll result={dp[n][0],cnt[n][0]}; res=max(res,result); return res; } int main() { if (fopen(taskname".inp","r")) { freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>k; for(i=1;i<=n;i++) cin>>a[i]; l=0;r=1e18; while(l<=r){ mid=(l+r)/2; ans=check(mid); if(ans.se<=k){ answer=max(answer,ans.fi+mid*ans.se); r=mid-1; }else l=mid+1; }cout<<answer; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 13220 KB | Output is correct |
2 | Correct | 54 ms | 13744 KB | Output is correct |
3 | Correct | 64 ms | 13964 KB | Output is correct |
4 | Correct | 59 ms | 13768 KB | Output is correct |
5 | Correct | 53 ms | 13696 KB | Output is correct |
6 | Correct | 55 ms | 13144 KB | Output is correct |
7 | Correct | 52 ms | 13324 KB | Output is correct |
8 | Correct | 54 ms | 13844 KB | Output is correct |
9 | Correct | 59 ms | 13384 KB | Output is correct |
10 | Correct | 59 ms | 13544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 12480 KB | Output is correct |
2 | Correct | 46 ms | 12924 KB | Output is correct |
3 | Correct | 50 ms | 12636 KB | Output is correct |
4 | Correct | 50 ms | 12824 KB | Output is correct |
5 | Correct | 53 ms | 13368 KB | Output is correct |
6 | Correct | 51 ms | 12440 KB | Output is correct |
7 | Correct | 49 ms | 13172 KB | Output is correct |
8 | Correct | 52 ms | 13748 KB | Output is correct |
9 | Correct | 62 ms | 13328 KB | Output is correct |
10 | Correct | 47 ms | 12856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 80 ms | 13648 KB | Output is correct |
2 | Correct | 89 ms | 13560 KB | Output is correct |
3 | Correct | 82 ms | 13760 KB | Output is correct |
4 | Correct | 84 ms | 13692 KB | Output is correct |
5 | Correct | 82 ms | 13644 KB | Output is correct |
6 | Correct | 81 ms | 13704 KB | Output is correct |
7 | Correct | 92 ms | 13768 KB | Output is correct |
8 | Correct | 79 ms | 13808 KB | Output is correct |
9 | Correct | 99 ms | 13908 KB | Output is correct |
10 | Correct | 75 ms | 13916 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 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 | 468 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 | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 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 | 468 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 | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 344 KB | Output is correct |
20 | Correct | 1 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 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 | 468 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 | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 344 KB | Output is correct |
20 | Correct | 1 ms | 344 KB | Output is correct |
21 | Correct | 1 ms | 344 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 1 ms | 348 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 1 ms | 508 KB | Output is correct |
27 | Correct | 1 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 1 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 13220 KB | Output is correct |
2 | Correct | 54 ms | 13744 KB | Output is correct |
3 | Correct | 64 ms | 13964 KB | Output is correct |
4 | Correct | 59 ms | 13768 KB | Output is correct |
5 | Correct | 53 ms | 13696 KB | Output is correct |
6 | Correct | 55 ms | 13144 KB | Output is correct |
7 | Correct | 52 ms | 13324 KB | Output is correct |
8 | Correct | 54 ms | 13844 KB | Output is correct |
9 | Correct | 59 ms | 13384 KB | Output is correct |
10 | Correct | 59 ms | 13544 KB | Output is correct |
11 | Correct | 46 ms | 12480 KB | Output is correct |
12 | Correct | 46 ms | 12924 KB | Output is correct |
13 | Correct | 50 ms | 12636 KB | Output is correct |
14 | Correct | 50 ms | 12824 KB | Output is correct |
15 | Correct | 53 ms | 13368 KB | Output is correct |
16 | Correct | 51 ms | 12440 KB | Output is correct |
17 | Correct | 49 ms | 13172 KB | Output is correct |
18 | Correct | 52 ms | 13748 KB | Output is correct |
19 | Correct | 62 ms | 13328 KB | Output is correct |
20 | Correct | 47 ms | 12856 KB | Output is correct |
21 | Correct | 80 ms | 13648 KB | Output is correct |
22 | Correct | 89 ms | 13560 KB | Output is correct |
23 | Correct | 82 ms | 13760 KB | Output is correct |
24 | Correct | 84 ms | 13692 KB | Output is correct |
25 | Correct | 82 ms | 13644 KB | Output is correct |
26 | Correct | 81 ms | 13704 KB | Output is correct |
27 | Correct | 92 ms | 13768 KB | Output is correct |
28 | Correct | 79 ms | 13808 KB | Output is correct |
29 | Correct | 99 ms | 13908 KB | Output is correct |
30 | Correct | 75 ms | 13916 KB | Output is correct |
31 | Correct | 1 ms | 344 KB | Output is correct |
32 | Correct | 0 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 | 468 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 | 348 KB | Output is correct |
40 | Correct | 0 ms | 348 KB | Output is correct |
41 | Correct | 0 ms | 344 KB | Output is correct |
42 | Correct | 0 ms | 348 KB | Output is correct |
43 | Correct | 0 ms | 348 KB | Output is correct |
44 | Correct | 0 ms | 348 KB | Output is correct |
45 | Correct | 0 ms | 348 KB | Output is correct |
46 | Correct | 1 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 348 KB | Output is correct |
48 | Correct | 0 ms | 348 KB | Output is correct |
49 | Correct | 0 ms | 344 KB | Output is correct |
50 | Correct | 1 ms | 344 KB | Output is correct |
51 | Correct | 1 ms | 344 KB | Output is correct |
52 | Correct | 1 ms | 348 KB | Output is correct |
53 | Correct | 1 ms | 348 KB | Output is correct |
54 | Correct | 1 ms | 348 KB | Output is correct |
55 | Correct | 1 ms | 348 KB | Output is correct |
56 | Correct | 1 ms | 508 KB | Output is correct |
57 | Correct | 1 ms | 348 KB | Output is correct |
58 | Correct | 1 ms | 348 KB | Output is correct |
59 | Correct | 1 ms | 348 KB | Output is correct |
60 | Correct | 1 ms | 348 KB | Output is correct |
61 | Correct | 96 ms | 13820 KB | Output is correct |
62 | Correct | 102 ms | 14012 KB | Output is correct |
63 | Correct | 86 ms | 13656 KB | Output is correct |
64 | Correct | 109 ms | 13652 KB | Output is correct |
65 | Correct | 109 ms | 13832 KB | Output is correct |
66 | Correct | 112 ms | 13740 KB | Output is correct |
67 | Correct | 104 ms | 13652 KB | Output is correct |
68 | Correct | 77 ms | 13752 KB | Output is correct |
69 | Correct | 72 ms | 13648 KB | Output is correct |
70 | Correct | 70 ms | 13392 KB | Output is correct |