Submission #435196

# Submission time Handle Problem Language Result Execution time Memory
435196 2021-06-23T05:11:37 Z Supersonic Stove (JOI18_stove) C++14
100 / 100
34 ms 2380 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
bool pc(pair<int,int> a,pair<int,int> b){
	return a.second-a.first<b.second-b.first;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,k;cin>>n>>k;vector<pair<int,int>> v;
	int pv;cin>>pv;
	for(int i=1;i<n;i++){int k;cin>>k;v.push_back({pv,k});pv=k;}
	sort(v.rbegin(),v.rend(),pc);
	//for(auto i:v){cerr<<i.first<<' '<<i.second<<endl;}
	long long s=n,r=n;
	while(r>k){
		int a,b;tie(a,b)=v.back();v.pop_back();r--;
		s+=(long long)b-(a+1);
	}
	cout<<s<<endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 320 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 320 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 34 ms 2244 KB Output is correct
17 Correct 26 ms 2348 KB Output is correct
18 Correct 28 ms 2380 KB Output is correct
19 Correct 26 ms 2368 KB Output is correct
20 Correct 27 ms 2304 KB Output is correct
21 Correct 26 ms 2356 KB Output is correct
22 Correct 26 ms 2320 KB Output is correct
23 Correct 27 ms 2244 KB Output is correct
24 Correct 33 ms 2252 KB Output is correct