이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define ull unsigned long long
#define len(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
using namespace std;
const ll MOD = 1e9 + 7;
ll power (ll a, ll b) {
ll result = 1;
for (int i = 1; i <= b; i++) result *= a;
return result;
}
ll binpow(ll a, ll b) {
if (b == 0) return 1;
if (b % 2 == 1) return binpow(a, b - 1) * a;
else return binpow(a, b / 2) * binpow(a, b / 2);
}
ll fact(int x) {
ll result = 1;
for (int i = 2; i <= x; i++) result *= i;
return result;
}
ll comb(int n, int k) {
return fact(n) / fact(k) / fact(n - k);
}
void dpcomb(){
int c[2][2];
c[1][1] = 1;
for (int n = 2; n <= 1000; n++) {
c[n][1] = n;
for (int k = 2; k <= n; k++) {
c[n][k] = (c[n - 1][k] + c[n - 1][k - 1]) % MOD;
}
}
}
int a[100001];
vector < int > p;
int main() {
//freopen("success.in", "r", stdin);
//freopen("success.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k >> a[1];
for (int i = 2; i <= n; i++) {
cin >> a[i];
p.pb(a[i - 1] + 1 - a[i]);
}
sort(all(p));
ll sum = 0;
for (int i = 0; i < k - 1; i++) {
sum += p[i];
}
cout << sum - a[1] + a[n] + 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |