Submission #587117

# Submission time Handle Problem Language Result Execution time Memory
587117 2022-07-01T10:43:05 Z proma Stove (JOI18_stove) C++17
100 / 100
26 ms 4036 KB
#include <bits/stdc++.h>

#define int long long
#define see(x) cout<<#x<<"="<<x<<"\n";
#define endl "\n"

using namespace std;

const int N = 1e5+5;

int n, k, t[N], pos[N];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
/*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
*/

    cin >> n >> k;

    vector <pair <int, int>> stop;
    for (int i = 0; i < n; i ++) {
        cin >> t[i];
    }
    for (int i = 0; i < n; i ++) {
        if (i + 1 < n) {
            stop.push_back({t[i+1] - t[i], i});
        }
    }

    sort(stop.rbegin(), stop.rend());

    for (int i = 0; i < k - 1; i ++) {
        pos[stop[i].second] = 1;
    }
    pos[n-1] = 1;

    int flag = 0, res = 0;
    for (int i = 0; i < n; i ++) {
        if (pos[i]) res ++;
        if (i and pos[i-1]) continue;
        if (i) res += t[i] - t[i-1];
    }

    cout << res << endl;

    return 0;
}

Compilation message

stove.cpp: In function 'int32_t main()':
stove.cpp:40:9: warning: unused variable 'flag' [-Wunused-variable]
   40 |     int flag = 0, res = 0;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 26 ms 3752 KB Output is correct
17 Correct 22 ms 3696 KB Output is correct
18 Correct 22 ms 3900 KB Output is correct
19 Correct 22 ms 3964 KB Output is correct
20 Correct 23 ms 3908 KB Output is correct
21 Correct 22 ms 3916 KB Output is correct
22 Correct 24 ms 4024 KB Output is correct
23 Correct 23 ms 4036 KB Output is correct
24 Correct 22 ms 3908 KB Output is correct