Submission #373690

# Submission time Handle Problem Language Result Execution time Memory
373690 2021-03-05T12:45:10 Z MertD014 Stove (JOI18_stove) C++17
100 / 100
25 ms 2052 KB
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define f1 first
#define f2 second
#define ll long long
#define pii pair<int,int>
#define fastio() cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)          //no scanf
#define fileio(code) freopen("code.in","r",stdin);freopen("code.out","w",stdout)  //file name
using namespace std;

//https://oj.uz/problem/JOI18_stove

int n,k,x,y,ans,mn=INT_MAX,mx=INT_MIN;
vector<int> v;

int main(){
	fastio();
	cin>>n>>k;
	cin>>x;
	mn=min(mn,x);
	mx=max(mx,x);
	for(int i=1;i<n;i++){
		cin>>y;
		mn=min(mn,y);
		mx=max(mx,y);
		v.pb(y-x-1);
		x=y;
	}
	sort(v.rbegin(),v.rend());
	for(int i=0;i<k-1;i++) ans+=v[i];
	cout<<mx-mn+1-ans;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 21 ms 1904 KB Output is correct
17 Correct 20 ms 1904 KB Output is correct
18 Correct 21 ms 1904 KB Output is correct
19 Correct 23 ms 1904 KB Output is correct
20 Correct 21 ms 2052 KB Output is correct
21 Correct 25 ms 1904 KB Output is correct
22 Correct 21 ms 1904 KB Output is correct
23 Correct 22 ms 1904 KB Output is correct
24 Correct 21 ms 1904 KB Output is correct