답안 #708079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708079 2023-03-11T03:50:50 Z yellowtoad Stove (JOI18_stove) C++17
100 / 100
63 ms 4752 KB
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

int n, k, a[100010], ans;
pair<int,int> d[100010];
vector<int> b;

signed main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i < n; i++) d[i] = {a[i+1]-a[i],i};
	sort(d+1,d+n,greater<pair<int,int>>());
	b.push_back(0);
	for (int i = 1; i < k; i++) b.push_back(d[i].second);
	b.push_back(n);
	for (int i = 1; i < b.size(); i++) ans += a[b[i]]+1-a[b[i-1]+1];
	cout << ans << endl;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:19:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for (int i = 1; i < b.size(); i++) ans += a[b[i]]+1-a[b[i-1]+1];
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 45 ms 3488 KB Output is correct
17 Correct 47 ms 3560 KB Output is correct
18 Correct 45 ms 3568 KB Output is correct
19 Correct 63 ms 3756 KB Output is correct
20 Correct 47 ms 4208 KB Output is correct
21 Correct 53 ms 4752 KB Output is correct
22 Correct 53 ms 4728 KB Output is correct
23 Correct 48 ms 4736 KB Output is correct
24 Correct 47 ms 4736 KB Output is correct