이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |