이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endline "\n"
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define lsb(i) i&(-i)
#define sz(i) (int)i.size()
typedef long long ll;
using namespace std;
const ll INF = 1e18L;
constexpr int mod = int(1e9) + 7;
ll t=1, n, k, cases = 0;
void solve(){
cin >> n >> k;
vector<ll> ar(n),sortar;
for(int i = 0; i < n; i++)cin >> ar[i];
for(int i = 0; i < n - 1; i++){
sortar.pb(ar[i + 1] - ar[i] - 1);
}
sort(sortar.begin(),sortar.end());
ll ans = n;
for(int i = 0; i < n - k; i++){
ans += sortar[i];
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
//cin>>t;
for(; cases < t; cases++)solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |