Submission #971848

#TimeUsernameProblemLanguageResultExecution timeMemory
971848SunbaeStove (JOI18_stove)C++17
100 / 100
18 ms3284 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 1e5 + 5; ll a[N]; signed main(){ int n; ll k; scanf("%d %lld", &n, &k); for(int i = 0; i<n; ++i) scanf("%lld", a+i); sort(a, a+n); vector<ll> v; for(int i = 0; i<n-1; ++i) v.push_back(a[i] - a[i+1]); sort(v.begin(), v.end()); ll ans = k + a[n-1] - a[0]; for(int i = 0; i<k-1; ++i) ans += v[i]; printf("%lld", ans); }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  int n; ll k; scanf("%d %lld", &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("%lld", a+i);
      |                           ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...