제출 #1294139

#제출 시각아이디문제언어결과실행 시간메모리
1294139kirakosyanStove (JOI18_stove)C++20
0 / 100
1 ms568 KiB
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<set> #include<map> #include<queue> #include<stack> #include<unordered_map> #include<unordered_set> using namespace std; using ll = long long; ll mod = 1e9 + 7; ll gcd(ll a, ll b) { if (b != 0) { return gcd(b, a % b); } else return a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll pv(ll a, ll b) { if (b == 0)return 1; ll res = pv(a, b / 2) % mod; if (b % 2 == 1) { return ((res * res) % mod * a) % mod; } else return (res * res) % mod; } void solve() { ll n, k; cin >> n >> k; vector<ll>v(n); for (ll i = 0; i < n; i++) { cin >> v[i]; } ll sum = v[n - 1]; vector<ll>a; sort(v.begin(), v.end()); for (ll i = 0; i < n - 1; i++) { a.push_back(v[i + 1] - v[i] - 1); } sort(a.rbegin(), a.rend()); for (ll i = 0; i < k - 1; i++) { sum -= (a[i]); } cout << sum << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); ll t = 1; //cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...