Submission #127221

# Submission time Handle Problem Language Result Execution time Memory
127221 2019-07-09T06:51:46 Z nhimnam120 Stove (JOI18_stove) C++14
100 / 100
28 ms 1528 KB
#include<bits/stdc++.h>
#pragma optimize(O3)
using namespace std;
vector<int> inp;
vector<int> pro;
signed main(){
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		int a;
		cin >> a;
		inp.push_back(a);
	}
	int diff=1;
	sort(inp.begin(),inp.end());
	for(int i=0;i<inp.size()-1;i++){
		if(inp[i+1]-inp[i]>1){
			diff++;
			pro.push_back(inp[i+1]-inp[i]-1);
		}
	}
	int match=diff-k;
	sort(pro.begin(),pro.end());
	if(match<=0){
		cout << n;
		return 0;
	}
	int ans=n;
	for(int i=0;i<match;i++){
		ans+=pro[i];
	}
	cout << ans;
}

Compilation message

stove.cpp:2:0: warning: ignoring #pragma optimize  [-Wunknown-pragmas]
 #pragma optimize(O3)
 
stove.cpp: In function 'int main()':
stove.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<inp.size()-1;i++){
              ~^~~~~~~~~~~~~
# 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 256 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 256 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 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 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 256 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 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 27 ms 1524 KB Output is correct
17 Correct 27 ms 1520 KB Output is correct
18 Correct 27 ms 1512 KB Output is correct
19 Correct 27 ms 1524 KB Output is correct
20 Correct 28 ms 1484 KB Output is correct
21 Correct 27 ms 1524 KB Output is correct
22 Correct 27 ms 1528 KB Output is correct
23 Correct 27 ms 1524 KB Output is correct
24 Correct 27 ms 1524 KB Output is correct