Submission #785118

#TimeUsernameProblemLanguageResultExecution timeMemory
785118AlkaratStove (JOI18_stove)C++14
100 / 100
48 ms900 KiB
#include <bits/stdc++.h> using namespace std; int n,k,x; long long ans; priority_queue<int,vector<int>,greater<int>>pq; int main() { cin>>n>>k>>x; int l=x,r=x+1; for(int i=2; i<=n; i++) { cin>>x; if(x==r) r=x+1; else { pq.push(x-r); ans+=r-l; l=x,r=x+1; } } ans+=r-l; while(pq.size()>=k) { ans+=pq.top(); pq.pop(); } cout<<ans; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:22:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     while(pq.size()>=k)
      |           ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...