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 <iostream>
#include <set>
#define MAXN 100000
using namespace std;
int vst[MAXN + 1];
multiset<int> tms; // set of all time between each visits, greatest to least
int main() {
int N, K;
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> vst[i];
}
for (int i = 1; i < N; i++) {
int between = vst[i] - vst[i - 1] - 1; // -1 to account for end time
tms.insert(-between); // negative to sort greatest to smallest
}
int total = vst[N-1] + 1 - vst[0]; // total time if only 1 candle used
int used = 1; // start with only 1 candle used for all visits
set<int>::iterator it;
for (it = tms.begin(); it != tms.end(); it++) {
if (used == K) break;
total += *it;
used++;
}
cout << total;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |