Submission #996384

#TimeUsernameProblemLanguageResultExecution timeMemory
996384preskoStove (JOI18_stove)C++14
0 / 100
0 ms348 KiB
#include<iostream> #include<vector> #include<algorithm> #define MAXN 100010 using namespace std; vector<int> order; int a[MAXN]; int main() { int n,k; ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=1;i<=n;i++) { cin>>a[i]; if(i>1)order.push_back(a[i]-a[i-1]); } if(k==1){cout<<a[n]+1-a[1]<<"\n";return 0;} if(k==n){cout<<n+1<<"\n";return 0;} sort(order.begin(),order.end()); int cntr=0,ans=0; for(int i=0;i<order.size();i++) { ans+=order[i]+1; cntr++; if(i>0) { if(order[i-1]==1)ans--; } if(cntr>=n-k)break; } cout<<ans+k-1<<"\n"; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<order.size();i++)
      |                 ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...