Submission #1109226

# Submission time Handle Problem Language Result Execution time Memory
1109226 2024-11-06T08:23:37 Z codinion Stove (JOI18_stove) C++14
100 / 100
45 ms 3792 KB
// 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

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 time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 35 ms 3780 KB Output is correct
17 Correct 36 ms 3780 KB Output is correct
18 Correct 35 ms 3744 KB Output is correct
19 Correct 36 ms 3780 KB Output is correct
20 Correct 35 ms 3748 KB Output is correct
21 Correct 38 ms 3772 KB Output is correct
22 Correct 35 ms 3792 KB Output is correct
23 Correct 45 ms 3772 KB Output is correct
24 Correct 35 ms 3772 KB Output is correct