Submission #41101

#TimeUsernameProblemLanguageResultExecution timeMemory
41101abekerStove (JOI18_stove)C++14
100 / 100
32 ms1624 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int N, K; int t[MAXN]; vector <int> gaps; void load() { scanf("%d%d", &N, &K); for (int i = 0; i < N; i++) scanf("%d", t + i); } int solve() { int last = t[0]; int cnt = 1, sol = 0; for (int i = 1; i < N; i++) if (t[i] - t[i - 1] > 1) { sol += t[i - 1] - last + 1; gaps.push_back(t[i] - t[i - 1] - 1); last = t[i]; cnt++; } sol += t[N - 1] - last + 1; sort(gaps.begin(), gaps.end()); for (int i = 0; i < cnt - K; i++) sol += gaps[i]; return sol; } int main() { load(); printf("%d\n", solve()); return 0; }

Compilation message (stderr)

stove.cpp: In function 'void load()':
stove.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K);
                       ^
stove.cpp:13:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", t + i);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...