제출 #41577

#제출 시각아이디문제언어결과실행 시간메모리
41577szawinisStove (JOI18_stove)C++14
100 / 100
34 ms2068 KiB
#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);
}

컴파일 시 표준 에러 (stderr) 메시지

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);
                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...