Submission #880987

#TimeUsernameProblemLanguageResultExecution timeMemory
880987theghostkingStove (JOI18_stove)C++17
100 / 100
56 ms5320 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n,k; cin >> n >> k; if (n==1){ cout << "1\n"; return 0; } int arr[n]; for (int i = 0; i<n; i++){ cin >> arr[i]; } sort(arr,arr+n); vector<bool> pres(n); pres[0] = true; priority_queue<pair<int,int>> pq; for (int i = 0; i<n-1; i++){ pq.push({arr[i+1]-arr[i],i}); } int kc = k; k--; while (k--){ pres[pq.top().second+1] = true; pq.pop(); } vector<int> nxt(n,-1); int tr = 0; for (int i = 1; i<n; i++){ if (pres[i]){ nxt[tr] = i-1; tr = i; } } int lst = arr[0]; int ind = 0; int ans = 0; for (int i = 0; i<n; i++){ if (pres[i]){ int nd = nxt[i]; if (nd == -1){ ans += (arr[n-1]-arr[i]+1); } else{ ans += (arr[nd]-arr[i]+1); } } } cout << ans; return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:24:9: warning: unused variable 'kc' [-Wunused-variable]
   24 |     int kc = k;
      |         ^~
stove.cpp:38:9: warning: unused variable 'lst' [-Wunused-variable]
   38 |     int lst = arr[0];
      |         ^~~
stove.cpp:39:9: warning: unused variable 'ind' [-Wunused-variable]
   39 |     int ind = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...