Submission #143792

#TimeUsernameProblemLanguageResultExecution timeMemory
143792WhipppedCreamStove (JOI18_stove)C++17
100 / 100
31 ms2404 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	vector<int> arr(n);
	for(int i = 0; i< n; i++) scanf("%d", &arr[i]);
	vector<int> gap;
	for(int i = 0; i+1< n; i++) gap.pb(arr[i+1]-arr[i]-1);
	sort(gap.begin(), gap.end());
	reverse(gap.begin(), gap.end());
	int res = arr[n-1]-arr[0]+1;
	for(int i = 0; i< k-1; i++) res -= gap[i];
	printf("%d\n", res);
}

Compilation message (stderr)

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