Submission #202175

# Submission time Handle Problem Language Result Execution time Memory
202175 2020-02-14T04:15:45 Z tri Stove (JOI18_stove) C++14
100 / 100
78 ms 2420 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

int main() {
    int N, K;
    cin >> N >> K;
    vi times(N);
    for (int i = 0; i < N; i++) {
        cin >> times[i];
    }
    sort(times.begin(), times.end());

    int sum = times[times.size() - 1] - times[0] + 1;

    vi spaces;
    for (int i = 0; i + 1 < N; i++) {
        int space = times[i + 1] - times[i] - 1;
        if (space > 0) {
            spaces.pb(space);
        }
    }
    sort(spaces.begin(), spaces.end());
    reverse(spaces.begin(), spaces.end());

    for (int i = 0; i < spaces.size() && i < K - 1; i++) {
        sum -= spaces[i];
    }
    cout << sum << endl;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < spaces.size() && i < K - 1; i++) {
                     ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 7 ms 376 KB Output is correct
11 Correct 7 ms 376 KB Output is correct
12 Correct 7 ms 380 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 7 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 7 ms 376 KB Output is correct
11 Correct 7 ms 376 KB Output is correct
12 Correct 7 ms 380 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 7 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 77 ms 2292 KB Output is correct
17 Correct 76 ms 2292 KB Output is correct
18 Correct 76 ms 2292 KB Output is correct
19 Correct 77 ms 2292 KB Output is correct
20 Correct 77 ms 2292 KB Output is correct
21 Correct 77 ms 2292 KB Output is correct
22 Correct 76 ms 2292 KB Output is correct
23 Correct 78 ms 2420 KB Output is correct
24 Correct 77 ms 2292 KB Output is correct