Submission #618021

#TimeUsernameProblemLanguageResultExecution timeMemory
618021as111Stove (JOI18_stove)C++14
100 / 100
83 ms6360 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...