이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> // PLEASE
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 300005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N, K;
ll V[MAXN];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
vector <ll> difs;
cin >> N >> K;
ll ans = (ll)K;
for(int i=0; i<N; i++) cin >> V[i];
for(int i=0; i+1<N; i++) {
difs.PB(V[i+1]-V[i]);
ans += V[i+1] - V[i];
}
sort(difs.begin(), difs.end());
reverse(difs.begin(), difs.end());
for(int i=0; i<K-1; i++) ans -= difs[i];
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |