답안 #650040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650040 2022-10-12T05:46:49 Z Kenpar Stove (JOI18_stove) C++17
100 / 100
28 ms 2776 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
#define endl '\n'
 
const ll MOD = 998244353;
const ll INF = 1e16;
const int INT_INF = 1e9;
const ll MAX = 1e6+1;

void solve(){
	int n;
	cin>>n;

	int k;
	cin>>k;

	vector<bool> merged(n, false);
	vector<int> arr(n);

	vector<pair<int,int>> dif;

	for(int i = 0; i < n; i++){
		cin>>arr[i];

		if(i != 0){
			dif.push_back({arr[i] - arr[i-1], i-1});
		}
	}

	sort(dif.begin(), dif.end() );

	ll ans = 0;

	for(pair<int,int> ch : dif){
		//cout<<ch.first<<" "<<ch.second<<endl;
	}

	for(int i = 0; i < n-k; i++){
		ans+=dif[i].first;
		merged[dif[i].second] = true;
	}

	for(int i = 0; i < n; i++){
		ans+=!merged[i];
	}

	cout<<ans;
}
 
 
int main()
{
	cin.tie(NULL);
	ios::sync_with_stdio(NULL);
	int t = 1;
 
	//cin >> t;
 
	while(t--){
		solve();
		cout<<endl;
	}
}

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:36:20: warning: variable 'ch' set but not used [-Wunused-but-set-variable]
   36 |  for(pair<int,int> ch : dif){
      |                    ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 22 ms 2772 KB Output is correct
17 Correct 22 ms 2668 KB Output is correct
18 Correct 21 ms 2764 KB Output is correct
19 Correct 23 ms 2756 KB Output is correct
20 Correct 22 ms 2772 KB Output is correct
21 Correct 23 ms 2772 KB Output is correct
22 Correct 21 ms 2772 KB Output is correct
23 Correct 21 ms 2776 KB Output is correct
24 Correct 28 ms 2768 KB Output is correct