답안 #127220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127220 2019-07-09T06:51:27 Z nhimnam120 Stove (JOI18_stove) C++14
100 / 100
28 ms 1652 KB
#include<bits/stdc++.h>
#pragma optimize(Ofast)
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(Ofast)
 
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++){
              ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 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 1496 KB Output is correct
17 Correct 27 ms 1524 KB Output is correct
18 Correct 27 ms 1524 KB Output is correct
19 Correct 27 ms 1524 KB Output is correct
20 Correct 27 ms 1524 KB Output is correct
21 Correct 26 ms 1520 KB Output is correct
22 Correct 27 ms 1652 KB Output is correct
23 Correct 27 ms 1520 KB Output is correct
24 Correct 28 ms 1524 KB Output is correct