Submission #650672

# Submission time Handle Problem Language Result Execution time Memory
650672 2022-10-14T16:06:16 Z Shin Stove (JOI18_stove) C++14
100 / 100
20 ms 2384 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, k; cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i ++) {
    cin >> a[i];
  }
  vector<int> gap;
  long long res = a[n] - a[1] + 1;
  for (int i = 2; i <= n; i ++) {
    gap.push_back(a[i] - a[i - 1] - 1);
  }
  sort(gap.begin(), gap.end());
  reverse(gap.begin(), gap.end());
  k --;
  for (int x: gap) {
    if ((-- k) < 0) {
      break;
    }
    res -= x;
  }
  cout << res;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 316 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 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 18 ms 2240 KB Output is correct
17 Correct 20 ms 2264 KB Output is correct
18 Correct 19 ms 2240 KB Output is correct
19 Correct 20 ms 2280 KB Output is correct
20 Correct 18 ms 2264 KB Output is correct
21 Correct 17 ms 2256 KB Output is correct
22 Correct 18 ms 2256 KB Output is correct
23 Correct 18 ms 2264 KB Output is correct
24 Correct 19 ms 2384 KB Output is correct