Submission #127310

# Submission time Handle Problem Language Result Execution time Memory
127310 2019-07-09T08:17:21 Z Clementime Stove (JOI18_stove) C++17
0 / 100
2 ms 376 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);
	set<ll> myset;
	ll num = 0;
	for(ll i = n - 2; i >= 0; i--){
		if(num != k - 1){
			num++;
			myset.insert(p[i].second);
		}
	}
	ll ans = 0;
	ll pos = 0;
	for(set<ll> :: iterator it = myset.begin(); it != myset.end(); it++){
		ans += (a[*it] - a[pos]);
		pos = *it + 1;
	}
	if(k == 1){
		cout << a[n - 1] - a[0] + 1;
	}
	else cout << ans + k;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -