Submission #171701

#TimeUsernameProblemLanguageResultExecution timeMemory
171701dennisstarStove (JOI18_stove)C++11
100 / 100
33 ms2480 KiB
#include <bits/stdc++.h>
using namespace std;
 
int n, k, t[100010];
priority_queue<int, vector<int>, greater<int> > pq;
 
int main() {
	scanf("%d %d", &n, &k);
	int ans=n, i;
	for (i=0; i<n; i++) scanf("%d", &t[i]);
	for (i=0; i<n-1; i++) pq.push(t[i+1]-t[i]-1);
	for (i=0; i<n-k; i++) { ans+=pq.top(); pq.pop(); }
	printf("%d\n", ans);
	return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:10:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i=0; i<n; i++) scanf("%d", &t[i]);
                      ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...