Submission #277854

# Submission time Handle Problem Language Result Execution time Memory
277854 2020-08-21T07:45:18 Z erkam Stove (JOI18_stove) C++17
100 / 100
25 ms 3100 KB
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<set>
#include<map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long lo;
const int mod=1000000007,N=500005;
lo a,b,c,d,e,f,g=1,h[N],arr[N];
string s;
vector<lo>v;

void solve(){
	cin >> a >> b;
	vector<lo>v;
	for(lo i=1;i<=a;i++){
		cin >> arr[i];
		if(i>1)v.pb(arr[i]-arr[i-1]-1);
	}
	sort(all(v));
	reverse(all(v));
	lo ans=arr[a]-arr[1]+1;
	for(lo i=0;i<b-1;i++){
		ans-=v[i];
	}
	cout << ans << endl;
}
 
int main(){
	#ifdef local
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// cin >> g;
	while(g--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 2 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 2 ms 544 KB Output is correct
16 Correct 24 ms 3100 KB Output is correct
17 Correct 21 ms 3064 KB Output is correct
18 Correct 22 ms 3064 KB Output is correct
19 Correct 21 ms 3064 KB Output is correct
20 Correct 24 ms 3064 KB Output is correct
21 Correct 21 ms 3064 KB Output is correct
22 Correct 21 ms 3064 KB Output is correct
23 Correct 25 ms 3056 KB Output is correct
24 Correct 25 ms 3064 KB Output is correct