이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |