Submission #657810

# Submission time Handle Problem Language Result Execution time Memory
657810 2022-11-11T10:18:59 Z OgradL Stove (JOI18_stove) C++14
100 / 100
48 ms 3520 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define p pair<int, int>
#define mkp make_pair
#define pb push_back

int main() {
    
    int N, K;
    cin >> N >> K;
    
    vector<ll> T(N);
    for (ll &n: T) cin >> n;
    
    vector<p> R;
    //vector<int> siz;
    int start = T[0];
    for (int i = 0; i < N; i++){
        if (i == N - 1){
            R.pb(mkp(start, T[i]+1));
            //cout << start << " " << T[i]+1 << "\n";
        } else if (T[i] + 1 != T[i + 1]){
            R.pb(mkp(start, T[i]+1));
            //siz.pb(T[i]+1 - start);
            //cout << start << " " << T[i]+1 << "\n";
            start = T[i + 1];
        }
    }
    //cout << "\n\n\n";
    
    vector<int> siz;
    for (int i = 0; i < R.size() - 1; i++){
        siz.pb(R[i+1].first - R[i].second);
        //cout << R[i].second << " " << R[i+1].first << " " << R[i+1].first - R[i].second << "\n";
    }
    
    
    sort(siz.begin(), siz.end(), greater<int>());
    
    ll sum = 0;
    for (int i = 0; i < K - 1 && i < siz.size(); i++){
        sum += siz[i];
        //cout << siz[i] << "\n";
    }
    //cout << T[N-1] << " " << T[0] << " " << sum << "\n";
    cout << T[N-1]+1-T[0]-sum << "\n";
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 0; i < R.size() - 1; i++){
      |                     ~~^~~~~~~~~~~~~~
stove.cpp:46:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < K - 1 && i < siz.size(); i++){
      |                                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 312 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 308 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 312 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 308 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 45 ms 3472 KB Output is correct
17 Correct 46 ms 3520 KB Output is correct
18 Correct 46 ms 3520 KB Output is correct
19 Correct 47 ms 3492 KB Output is correct
20 Correct 44 ms 3488 KB Output is correct
21 Correct 48 ms 3472 KB Output is correct
22 Correct 45 ms 3480 KB Output is correct
23 Correct 44 ms 3456 KB Output is correct
24 Correct 44 ms 3420 KB Output is correct