Submission #587113

#TimeUsernameProblemLanguageResultExecution timeMemory
587113promaStove (JOI18_stove)C++17
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> #define int long long #define see(x) cout<<#x<<"="<<x<<"\n"; #define endl "\n" using namespace std; const int N = 1e5+5; int n, k, t[N], pos[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); /* freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); */ cin >> n >> k; vector <pair <int, int>> stop; for (int i = 0; i < n; i ++) { cin >> t[i]; } for (int i = 0; i < n; i ++) { if (i + 1 < n) { stop.push_back({t[i+1] - t[i], i}); } } sort(stop.rbegin(), stop.rend()); for (int i = 0; i < k - 1; i ++) { pos[stop[i].second] = 1; } int flag = 0, res = 0; for (int i = 0; i < n; i ++) { if (pos[i]) res ++; if (i and pos[i-1]) continue; res += t[i] - t[i-1]; } cout << res << endl; return 0; }

Compilation message (stderr)

stove.cpp: In function 'int32_t main()':
stove.cpp:39:9: warning: unused variable 'flag' [-Wunused-variable]
   39 |     int flag = 0, res = 0;
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...