답안 #41101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41101 2018-02-12T18:09:14 Z abeker Stove (JOI18_stove) C++14
100 / 100
32 ms 1624 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 5;

int N, K;
int t[MAXN];
vector <int> gaps;

void load() {
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; i++)
		scanf("%d", t + i);
}

int solve() {
	int last = t[0];
	int cnt = 1, sol = 0;
	for (int i = 1; i < N; i++)
		if (t[i] - t[i - 1] > 1) {
			sol += t[i - 1] - last + 1;
			gaps.push_back(t[i] - t[i - 1] - 1);
			last = t[i];
			cnt++;
		}
	sol += t[N - 1] - last + 1;
	
	sort(gaps.begin(), gaps.end());
	for (int i = 0; i < cnt - K; i++)
		sol += gaps[i];
	
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Compilation message

stove.cpp: In function 'void load()':
stove.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K);
                       ^
stove.cpp:13:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", t + i);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 3 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 3 ms 624 KB Output is correct
16 Correct 27 ms 1624 KB Output is correct
17 Correct 28 ms 1624 KB Output is correct
18 Correct 28 ms 1624 KB Output is correct
19 Correct 28 ms 1624 KB Output is correct
20 Correct 29 ms 1624 KB Output is correct
21 Correct 31 ms 1624 KB Output is correct
22 Correct 29 ms 1624 KB Output is correct
23 Correct 32 ms 1624 KB Output is correct
24 Correct 28 ms 1624 KB Output is correct