Submission #99567

#TimeUsernameProblemLanguageResultExecution timeMemory
99567lovemathboyStove (JOI18_stove)C++14
100 / 100
43 ms2336 KiB
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> a; priority_queue<int> pq; int main() { scanf("%d %d", &n, &k); a.resize(n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (i > 0) { pq.push(a[i] - a[i-1] - 1); } } int ans = a[n-1] - a[0] + 1; while (k > 1) { k--; ans -= pq.top(); pq.pop(); } printf("%d\n", ans); return 0; }

Compilation message (stderr)

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