Submission #1113284

#TimeUsernameProblemLanguageResultExecution timeMemory
1113284hpesojStove (JOI18_stove)C++17
100 / 100
26 ms3388 KiB
#include <bits/stdc++.h>
#define int long long
#define pi pair<int, int>
#define ppi pair<pi, int>
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << '\n'
#define debug2(x, y) cout << #x << ": " << x << ' ' << #y << ": " << y << '\n'
#define debug3(x, y, z) cout << #x << ": " << x << ' ' << #y << ": " << y << ' ' << #z << ": " << z << '\n'
using namespace std;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int inf = 1e18+5, mod = 1000000007;
signed main(){
	ios::sync_with_stdio(0), cin.tie(0);
	int n, k; cin >> n >> k;
	int t[n+1];
	for(int i = 1; i <= n; i++) cin >> t[i];
	int ans = n;
	priority_queue <int, vector <int>, greater <int>> pq;
	for(int i = 2; i <= n; i++) if(t[i] - t[i-1] > 1) pq.push(t[i] - t[i-1] - 1);
	while(pq.size() >= k) ans += pq.top(), pq.pop();
	cout << ans;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:25:18: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   25 |  while(pq.size() >= k) ans += pq.top(), pq.pop();
      |        ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...