Submission #154329

#TimeUsernameProblemLanguageResultExecution timeMemory
154329ivandasfsStove (JOI18_stove)C++14
100 / 100
30 ms2144 KiB
#include <iostream>
#include <algorithm>

using namespace std;

int a[100005];
int b[100005];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	int sol = n;
	for (int i=0 ; i<n ; i++) {
		scanf("%d", a+i);
	}
	sort(a, a+n);
	for (int i=0 ; i<n-1 ; i++) {
		b[i] = a[i+1] - a[i] - 1;
	}
	sort(b, b+n-1);
	for (int i=0 ; i<n-k ; i++) {
		sol += b[i];
	}
	printf("%d\n", sol);
	return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:11: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:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+i);
   ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...