# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
240610 |
2020-06-20T09:16:35 Z |
mhy908 |
Feast (NOI19_feast) |
C++14 |
|
1000 ms |
11896 KB |
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=10000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;
int n, k;
LL arr[300010], dp[300010][2], cnt[300010][2];
int solve(LL x){
dp[0][0]=-llinf;
dp[0][1]=0;
for(int i=1; i<=n; i++){
if(dp[i-1][0]>dp[i-1][1]-x)dp[i][0]=dp[i-1][0]+arr[i], cnt[i][0]=cnt[i-1][0];
else dp[i][0]=dp[i-1][1]+arr[i]-x, cnt[i][0]=cnt[i-1][1]+1;
tie(dp[i][1], cnt[i][1])=max(tie(dp[i-1][0], cnt[i][0]), tie(dp[i-1][1], cnt[i][1]));
}
if(dp[n][0]>dp[n][1])return cnt[n][0];
return cnt[n][1];
}
int main(){
scanf("%d %d", &n, &k);
for(int i=1; i<=n; i++){
scanf("%lld", &arr[i]);
arr[i]*=2;
}
LL l=0, r=llinf;
while(l<r){
LL mid=(l+r)/2;
if(solve(mid*2+1)>=k)l=mid;
else r=mid+1;
}
solve(l*2);
printf("%lld", max(dp[n][0], dp[n][1])/2+l*k);
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~
feast.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &arr[i]);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
11640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
11768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
11896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
11640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |