Submission #554818

# Submission time Handle Problem Language Result Execution time Memory
554818 2022-04-29T13:11:11 Z d4xn Stove (JOI18_stove) C++17
0 / 100
1 ms 212 KB
#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define LB lower_bound
#define UB upper_bound
#define ii pair<int, int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define vii vector<ii>
#define vvii vector<vii>
#define vll vector<ll>
#define vld vector<ld>
#define pld pair<ld, ld>
#define vpld vector<pair<ld, ld>>

int n, k;
vi v;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> k;
  v.resize(n);
  for (int &i : v) cin >> i;
  sort(all(v));

  vi dis;
  for (int i = 0; i+1 < n; i++) {
    dis.pb(v[i+1]-v[i]+1);
  }
  sort(rall(dis));

  int ans = 0;
  int x = n;
  while (k < x) {
    ans += dis[x-2];
    dis.pop_back();
    x--;
  }

  cout << ans + (n-k) << "\n";

  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -