# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1122162 | Aviansh | Feast (NOI19_feast) | C++17 | 1071 ms | 24104 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin >> n >> k;
vector<long long> arr(n);
for(int i = 0;i<n;i++){
cin >> arr[i];
}
long long ans = 0;
while(arr.size()>1){
multiset<long long>topk;
vector<long long>temp;
temp.push_back(arr[0]);
for(int i = 1;i<n;i++){
if(temp.back()<0&&arr[i]<0){
temp.back()+=arr[i];
}
else if(temp.back()>0&&arr[i]>0){
temp.back()+=arr[i];
}
else{
temp.push_back(arr[i]);
}
}
arr=temp;
for(int i =0;i<arr.size();i++){
topk.insert(arr[i]);
}
while(topk.size()>k){
topk.erase(topk.begin());
}
long long sum = 0;
for(long long a : topk){
sum+=a;
}
ans=max(ans,sum);
int minind = min_element(arr.begin(),arr.end())-arr.begin();
for(int i = 0;i<arr.size();i++){
if(arr[i]<=0&&arr[i]>arr[minind]){
minind=i;
}
}
if(minind==0||minind==arr.size()-1){
arr.erase(arr.begin()+minind);
continue;
}
if(minind!=arr.size()-1){
arr[minind]+=arr[minind+1];
arr.erase(arr.begin()+minind+1);
}
if(minind){
arr[minind]+=arr[minind-1];
arr.erase(arr.begin()+minind-1);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |