Submission #127315

# Submission time Handle Problem Language Result Execution time Memory
127315 2019-07-09T08:20:22 Z Clementime Stove (JOI18_stove) C++17
100 / 100
92 ms 4248 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define FOR(i, l, r) for(ll i = l; i <= r; i++)
ll a[100005], val[100005];
pair<ll, ll> p[100005];

bool tmp(pair<ll, ll> A, pair<ll, ll> B){
	if(A.first != B.first) return A.first < B.first;
	else return A.second <= B.second;
}

int main(){
	ll n, k;
	cin >> n >> k;
	FOR(i, 0, n - 1){
		cin >> a[i];
	}
	FOR(i, 0, n - 2){
		val[i] = a[i + 1] - a[i];
		p[i].first = val[i];
		p[i].second = i;
	}
	sort(p, p + n - 1, tmp);
	ll ans = 0;
	FOR(i, 0, n - k - 1){
		ans += p[i].first;
	}
	cout << ans + k;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 4 ms 380 KB Output is correct
14 Correct 5 ms 476 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 4 ms 380 KB Output is correct
14 Correct 5 ms 476 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 90 ms 4220 KB Output is correct
17 Correct 89 ms 4016 KB Output is correct
18 Correct 90 ms 4128 KB Output is correct
19 Correct 90 ms 4088 KB Output is correct
20 Correct 92 ms 4088 KB Output is correct
21 Correct 89 ms 4216 KB Output is correct
22 Correct 89 ms 3960 KB Output is correct
23 Correct 89 ms 4092 KB Output is correct
24 Correct 89 ms 4248 KB Output is correct