This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
int main(){
ios_base::sync_with_stdio(false);
int N,K,x;
vi guests;
vector< ii > te;
cin>>N>>K;
for(int i=0;i<N;i++){
cin>>x;
guests.push_back(x);
}
// Tiempos de Espera
for(int i=0;i<N-1;i++){
te.push_back(ii(guests[i+1]-guests[i],i+1));
}
sort(te.rbegin(),te.rend());
vi posiciones;
for(int i=0;i<K-1;i++){
posiciones.push_back(te[i].second);
}
sort(posiciones.begin(),posiciones.end());
int pos_anterior = 0;
int tiempo = 0;
for(auto p: posiciones){
tiempo += guests[p-1]-guests[pos_anterior]+1;
pos_anterior = p;
}
tiempo += guests[N-1]-guests[pos_anterior]+1;
cout<<tiempo<<"\n";
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... |