Submission #82920

#TimeUsernameProblemLanguageResultExecution timeMemory
82920memetkagan44Split the sequence (APIO14_sequence)C++11
0 / 100
12 ms1656 KiB
#include<bits/stdc++.h> using namespace std; vector<int> v; queue<pair<int,int> > q; int n,k,a,top[100005]; long long ans; int main(){ scanf("%d %d",&n,&k); for(int i=1;i<=n;i++){ scanf("%d",&a); top[i]=top[i-1]+a; } q.push(make_pair(1,n)); while(!q.empty() && k>0){ k--; int l=q.front().first,r=q.front().second; q.pop(); int i=l; for(;top[i]-top[l-1]<=(top[r]-top[l-1])/2;i++); if(abs((top[i-1]-top[l-1])-(top[r]-top[l-1])/2)<(top[i]-top[l-1])-(top[r]-top[l-1])/2) i--; ans+=(top[i]-top[l-1])*(top[r]-top[i]); v.push_back(i); q.push(make_pair(l,i)); q.push(make_pair(i+1,r)); } printf("%lld\n",ans); for(int i=0;i<v.size();i++){ printf("%d",v[i]); if(i<v.size()-1) printf(" "); else printf("\n"); } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:28:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++){
                 ~^~~~~~~~~
sequence.cpp:30:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i<v.size()-1)
            ~^~~~~~~~~~~
sequence.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
sequence.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a);
         ~~~~~^~~~~~~~~
#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...