Submission #971847

#TimeUsernameProblemLanguageResultExecution timeMemory
971847SunbaeStove (JOI18_stove)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 5; int a[N]; signed main(){ int n, k; scanf("%d %d", &n, &k); for(int i = 0; i<n; ++i) scanf("%d", a+i); sort(a, a+n); using T = pair<ll,int>; priority_queue<T, vector<T>, greater<T>> pq; for(int i = 1; i<n-1; ++i) pq.emplace(a[i]-a[i+1], i); ll ans = k + (a[n-1] - a[0]); for(int i = 0; i<k-1; ++i) ans += pq.top().first; pq.pop(); printf("%lld", ans); }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:14:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   14 |  for(int i = 0; i<k-1; ++i) ans += pq.top().first; pq.pop();
      |  ^~~
stove.cpp:14:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   14 |  for(int i = 0; i<k-1; ++i) ans += pq.top().first; pq.pop();
      |                                                    ^~
stove.cpp:7:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  int n, k; scanf("%d %d", &n, &k);
      |            ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:8:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  for(int i = 0; i<n; ++i) scanf("%d", a+i);
      |                           ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...