| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355362 | Aviansh | Feast (NOI19_feast) | C++17 | 114 ms | 12164 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
array<int,2> fin(int arr[], int lam, int n){
array<int,2>dp[n][2];
//{sum,num}
dp[0][1]={arr[0]-lam,1};
dp[0][0]={0,0};
for(int i = 1;i<n;i++){
dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
dp[i][1]=max((array<int,2>){dp[i-1][1][0]+arr[i],dp[i-1][1][1]},(array<int,2>){dp[i-1][0][0]+arr[i]-lam,dp[i-1][0][1]+1});
}
return max(dp[n-1][0],dp[n-1][1]);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin >> n >> k;
int arr[n];
for(int &i : arr){
cin >> i;
}
int lo = 0;
int hi = 1e18;
while(lo<hi){
int mid = (lo+hi)/2;
array<int,2>a=fin(arr,mid,n);
if(a[1]<=k){
hi=mid;
}
else{
lo=mid+1;
}
}
int ans = fin(arr,lo,n)[0]+lo*k;
cout << ans;
return 0;
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
