답안 #754604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754604 2023-06-08T06:53:34 Z TsotneSV Stove (JOI18_stove) C++14
100 / 100
25 ms 1368 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define ff first
#define ss second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define ins insert
#define endl "\n"
#define flush fflush(stdout)
#define deb(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x<<" "<<x<<endl
const ll INF=1e18,MOD=1e9+7,MAXN=1e5+5;

int tt=1,n,k;
void solve(){
	cin>>n>>k; int A[n]; priority_queue<int> pq;
	
	for(int i=0;i<n;i++) {
		cin>>A[i];
	} sort(A,A+n);
	
	for(int i=1;i<n;i++) pq.push(A[i] - A[i-1]);
	int ans = 1; k--;
	while(k) {
		ans++;
		pq.pop(); k--;
	}
	
	while(pq.size()) {
		ans += pq.top(); pq.pop();
	} deb(ans);
	
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
   // cin>>tt;
    while(tt--){
        solve();
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 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 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 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 340 KB Output is correct
16 Correct 22 ms 1368 KB Output is correct
17 Correct 22 ms 1368 KB Output is correct
18 Correct 23 ms 1352 KB Output is correct
19 Correct 25 ms 1352 KB Output is correct
20 Correct 23 ms 1368 KB Output is correct
21 Correct 22 ms 1368 KB Output is correct
22 Correct 23 ms 1368 KB Output is correct
23 Correct 23 ms 1352 KB Output is correct
24 Correct 22 ms 1368 KB Output is correct