Submission #753460

#TimeUsernameProblemLanguageResultExecution timeMemory
753460IvanJStove (JOI18_stove)C++17
100 / 100
32 ms2256 KiB
#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e5 + 5;

int n, k;
int t[maxn];

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0;i < n;i++) 
		scanf("%d", t + i);
	
	sort(t, t + n);
	int T = t[n - 1] - t[0] + 1;
	
	vector<int> v;
	for(int i = 1;i < n;i++) 
		v.pb(t[i] - t[i - 1] - 1);
	sort(all(v));
	reverse(all(v));
	for(int i = 0;i < k - 1;i++) 
		T -= v[i];
	printf("%d\n", T);
	return 0;
}

Compilation message (stderr)

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