답안 #41577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41577 2018-02-19T13:04:45 Z szawinis Stove (JOI18_stove) C++14
100 / 100
34 ms 2068 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+1;

int n, k, ans, a[N];
priority_queue<int> segs;
int main() {
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%d", a+i);
		if(i > 1 && a[i] - a[i-1] > 1) segs.push(a[i] - a[i-1] - 1);
	}
	ans = a[n] - a[1] + 1;
	for(int i = 1; i < k && !segs.empty(); i++) {
		ans -= segs.top();
		segs.pop();
	}
	printf("%d", ans);
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:8:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
                        ^
stove.cpp:10:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+i);
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 472 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 2 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 472 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 2 ms 584 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 2 ms 616 KB Output is correct
14 Correct 2 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 472 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 2 ms 584 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 2 ms 616 KB Output is correct
14 Correct 2 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 22 ms 1896 KB Output is correct
17 Correct 22 ms 2068 KB Output is correct
18 Correct 23 ms 2068 KB Output is correct
19 Correct 26 ms 2068 KB Output is correct
20 Correct 32 ms 2068 KB Output is correct
21 Correct 33 ms 2068 KB Output is correct
22 Correct 34 ms 2068 KB Output is correct
23 Correct 33 ms 2068 KB Output is correct
24 Correct 32 ms 2068 KB Output is correct