Submission #542048

#TimeUsernameProblemLanguageResultExecution timeMemory
542048lunchboxStove (JOI18_stove)C++17
100 / 100
20 ms1696 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k, ans; scanf("%d%d", &n, &k), k--; vector<int> a(n); for (int &x : a) scanf("%d", &x); ans = a[n - 1] - a[0] + 1; for (int i = 0; i + 1 < n; i++) a[i] = a[i + 1] - a[i] - 1; a.pop_back(); sort(a.rbegin(), a.rend()); for (int i = 0; i < k; i++) ans -= a[i]; printf("%d\n", ans); return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:6:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |  scanf("%d%d", &n, &k), k--;
      |  ~~~~~^~~~~~~~~~~~~~~~
stove.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...