Submission #64458

#TimeUsernameProblemLanguageResultExecution timeMemory
64458elitewantsyouStove (JOI18_stove)C++14
100 / 100
43 ms10476 KiB
#include <bits/stdc++.h> #define fi first #define se second #define fin(s) freopen( s, "r", stdin ); #define fout(s) freopen( s, "w", stdout ); const long long N = 100100; const long long Q = N * 30; const long long mod = 998244353; const long long MAGIC = 30; using namespace std; int n; int k; int a[N]; vector < int > v; void solve() { cin >> n >> k; long long ans = 0; for(int i = 1; i <= n; i++){ cin >> a[i]; } sort(a + 1, a + n + 1); for(int i = 2; i <= n; i++){ ans += a[i] - a[i - 1]; v.push_back(a[i] - a[i - 1]); } sort(v.begin(), v.end()); while(v.size() > n - k){ ans -= v.back(); v.pop_back(); } cout << ans + k << "\n"; } bool mtest = false; int main() { //fin("input.txt"); //fout("output.txt"); //fin("island.in"); //fout("island.out"); ios_base::sync_with_stdio(0); int TE = 1; if(mtest) cin >> TE; while(TE--) solve(); return 0; }

Compilation message (stderr)

stove.cpp: In function 'void solve()':
stove.cpp:33:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(v.size() > n - k){
               ~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...