답안 #103351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103351 2019-03-29T22:47:53 Z tincamatei Stove (JOI18_stove) C++14
100 / 100
38 ms 2176 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 100000;

int t[MAX_N];
int dist[MAX_N - 1];

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n, k, rez;

	fscanf(fin, "%d%d", &n, &k);

	for(int i = 0; i < n; ++i)
		fscanf(fin, "%d", &t[i]);

	rez = 1;
	for(int i = 0; i < n - 1; ++i) {
		dist[i] = t[i + 1] - t[i] - 1;
		rez = rez + t[i + 1] - t[i];
	}
	
	sort(dist, dist + n - 1);

	for(int i = 0; i < k - 1; ++i)
		rez = rez - dist[n - i - 2];

	fprintf(fout, "%d", rez);

	fclose(fin);
	fclose(fout);
	return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:21:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d", &n, &k);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
stove.cpp:24:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d", &t[i]);
   ~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 27 ms 2164 KB Output is correct
17 Correct 25 ms 2040 KB Output is correct
18 Correct 38 ms 2040 KB Output is correct
19 Correct 24 ms 2048 KB Output is correct
20 Correct 28 ms 2048 KB Output is correct
21 Correct 26 ms 2048 KB Output is correct
22 Correct 29 ms 2168 KB Output is correct
23 Correct 24 ms 2176 KB Output is correct
24 Correct 24 ms 2040 KB Output is correct