Submission #618021

# Submission time Handle Problem Language Result Execution time Memory
618021 2022-08-01T19:22:09 Z as111 Stove (JOI18_stove) C++14
100 / 100
83 ms 6360 KB
#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
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 62 ms 6308 KB Output is correct
17 Correct 73 ms 6228 KB Output is correct
18 Correct 82 ms 6360 KB Output is correct
19 Correct 59 ms 6336 KB Output is correct
20 Correct 63 ms 6344 KB Output is correct
21 Correct 63 ms 6340 KB Output is correct
22 Correct 83 ms 6340 KB Output is correct
23 Correct 80 ms 6284 KB Output is correct
24 Correct 60 ms 6256 KB Output is correct