Submission #1109226

#TimeUsernameProblemLanguageResultExecution timeMemory
1109226codinionStove (JOI18_stove)C++14
100 / 100
45 ms3792 KiB
// https://oj.uz/problem/view/JOI18_stove #include <iostream> #include <algorithm> #include <vector> typedef long long ll; using namespace std; int main() { int N,K; cin>>N; cin>>K; ll* gg = new ll[N]; for(int i=0;i<N;i++) { cin>>gg[i]; } sort(gg, gg+N); vector<ll> active; vector<ll> inactive; ll totact = 0; ll curract = 1; for(int i = 1;i<N; i++) { if(gg[i] - gg[i-1] == 1) { curract++; } else { inactive.push_back(gg[i]-gg[i-1]-1); active.push_back(curract); totact+=curract; curract = 1; } } totact+=curract; active.push_back(curract); if(active.size() > K) { ll diff = active.size()-K; sort(inactive.begin(), inactive.end()); for(ll i = 0;i<diff;i++) totact += inactive[i]; } cout<<totact<<endl; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:40:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     if(active.size() > K)
      |        ~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...