이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
///* __ __ __ */
///* ====== _ /| /| __ _ / | | /| | @ | | | | / /| |\ | / | | @ | / */
///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */
///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */
///*
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vi> vv;
const int N = 2e6+4, inf = 1e8;
void solve(){
int n, k;
cin >> n >> k;
int a[n+1]{};
for(int i = 0; i < n; i++)cin >> a[i];
sort(a, a+n);
priority_queue<pii> v;
for(int i = 0; i < n-1; i++){
v.push({a[i+1]-a[i], i});
}
int of[n]{};
k--;
of[n-1] = 1;
while(k--){
of[v.top().ss]=1;
v.pop();
}
int ans = 0, l = a[0];
for(int i = 0; i < n; i++){
if(of[i]){
ans+=a[i]-l+1;
l = a[i+1];
}
}cout << ans << '\n';
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int test = 1;
//~ cin >> test;
while(test--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |