Submission #977955

# Submission time Handle Problem Language Result Execution time Memory
977955 2024-05-08T14:31:53 Z kilkuwu Stove (JOI18_stove) C++17
100 / 100
25 ms 2468 KB
#include <bits/stdc++.h>

#define nl '\n'

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, K;
  std::cin >> N >> K;

  std::vector<int> T(N);
  for (int i = 0; i < N; i++) {
    std::cin >> T[i];
  }

  std::sort(T.begin(), T.end());

  // split em into K parts such that a - b + .... + b - a
  // dp[i][k] = a[i] + 1 + min(dp[j][k - 1] - a[j + 1])
  // dp[i][k] = // slope trick ? 

  // dp[i][k] = // e
  // O(k * n) is easy
  // -a[j + 1] + a[j]
  // a[1] + a[n]
  // getting the k smallest lol

  std::priority_queue<int, std::vector<int>, std::greater<int>> pq;

  for (int i = 0; i + 1 < N; i++) {
    pq.push(T[i] - T[i + 1] + 1);
  }

  // 2 - 3
  // 4 - 6
  // -1 
  // -2

  int ans = T[N - 1] + 1 - T[0];

  // minimal lol

  K--;
  while (K > 0 && pq.size() && pq.top() < 0) {
    ans += pq.top();
    pq.pop();
    K--;
  }

  std::cout << ans << nl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 14 ms 2272 KB Output is correct
17 Correct 11 ms 2256 KB Output is correct
18 Correct 11 ms 2252 KB Output is correct
19 Correct 12 ms 2380 KB Output is correct
20 Correct 17 ms 2272 KB Output is correct
21 Correct 20 ms 2380 KB Output is correct
22 Correct 23 ms 2268 KB Output is correct
23 Correct 22 ms 2384 KB Output is correct
24 Correct 25 ms 2468 KB Output is correct