Submission #1292944

#TimeUsernameProblemLanguageResultExecution timeMemory
1292944dm10r7Stove (JOI18_stove)C++20
100 / 100
15 ms2340 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int n, k; scanf("%lld %lld", &n, &k); vector<int> t(n); for (int i = 0; i < n; i++) { scanf("%lld", &t[i]); } int ans = t.back() - t[0] + 1; vector<int> gap; for (int i = 0; i < n - 1; i++) { gap.push_back(t[i + 1] - t[i] - 1); } sort(gap.rbegin(), gap.rend()); for (int i = 0; i < k - 1 && i < (int)gap.size(); i++) { ans -= gap[i]; } printf("%lld\n", ans); return 0; } /* dm10r7 */

Compilation message (stderr)

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