Submission #1122162

#TimeUsernameProblemLanguageResultExecution timeMemory
1122162AvianshFeast (NOI19_feast)C++17
4 / 100
1071 ms24104 KiB
#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)

feast.cpp: In function 'int main()':
feast.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int i =0;i<arr.size();i++){
      |                      ~^~~~~~~~~~~
feast.cpp:34:26: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         while(topk.size()>k){
      |               ~~~~~~~~~~~^~
feast.cpp:43:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int i = 0;i<arr.size();i++){
      |                       ~^~~~~~~~~~~
feast.cpp:48:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         if(minind==0||minind==arr.size()-1){
      |                       ~~~~~~^~~~~~~~~~~~~~
feast.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if(minind!=arr.size()-1){
      |            ~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...