Submission #145592

#TimeUsernameProblemLanguageResultExecution timeMemory
145592mat_vStove (JOI18_stove)C++14
100 / 100
29 ms3316 KiB
#include <bits/stdc++.h> #define mod 1000000007 #define pb push_back #define mid(l, r) ((l)+(r))/2 #define len(a) (a).length() #define sz(a) (a).size() #define xx first #define yy second #define inf int(2e9) #define ff(i, a, b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i, a, b) for(int (i) = (a); (i) >= (b); --(i)) using namespace std; typedef long long ll; typedef pair<int,int> pii; int n,k; ll niz[300005]; vector<ll>val; ll res; int main() { ios_base::sync_with_stdio(false); cin >> n >> k; ff(i,0,n - 1){ cin >> niz[i]; } sort(niz, niz + n); ff(i,0,n-2){ val.pb(niz[i] - niz[i + 1]); //cout << niz[i] - niz[i+1] << endl; } int tmpk = k; sort(val.begin(), val.end()); for(auto c:val){ if(k==1)break; res += c; k--; if(k == 1)break; } res += niz[n-1]; res -= niz[0]; cout << res + tmpk; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...