답안 #50503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50503 2018-06-11T08:42:57 Z gnoor Stove (JOI18_stove) C++17
100 / 100
33 ms 10524 KB
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int tbl[100100];

int main() {
	int n,k;
	scanf("%d%d",&n,&k);
	vector<int> dif;
	
	int a;
	int b;

	for (int i=0;i<n;i++) {
		scanf("%d",&tbl[i]);
		if (i) {
			dif.push_back(tbl[i]-tbl[i-1]-1);
		}
		if (!i) a=tbl[i];
		b=tbl[i];
	}
	sort(dif.begin(),dif.end());
	//for (int i=0;i<n-1;i++) {
		//printf("%d\n",dif[i]);
	//}
	int ans=b-a;
	//printf("%d %d\n",a,b);
	for (int i=0;i<k-1;i++) {
		//printf("i %d\n",i);
		//printf("%d\n",dif[n-i-2]);
		ans-=dif[n-i-2];	
	}		
	printf("%d\n",ans+1);
	return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
stove.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&tbl[i]);
   ~~~~~^~~~~~~~~~~~~~
stove.cpp:29:6: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int ans=b-a;
      ^~~
stove.cpp:29:6: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 648 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 648 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 3 ms 776 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 784 KB Output is correct
14 Correct 3 ms 876 KB Output is correct
15 Correct 2 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 648 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 3 ms 776 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 784 KB Output is correct
14 Correct 3 ms 876 KB Output is correct
15 Correct 2 ms 908 KB Output is correct
16 Correct 27 ms 2728 KB Output is correct
17 Correct 27 ms 3744 KB Output is correct
18 Correct 26 ms 4708 KB Output is correct
19 Correct 30 ms 5688 KB Output is correct
20 Correct 27 ms 6796 KB Output is correct
21 Correct 29 ms 7632 KB Output is correct
22 Correct 31 ms 8592 KB Output is correct
23 Correct 27 ms 9560 KB Output is correct
24 Correct 33 ms 10524 KB Output is correct