Submission #157772

#TimeUsernameProblemLanguageResultExecution timeMemory
157772ZwariowanyMarcinStove (JOI18_stove)C++14
100 / 100
82 ms6492 KiB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define ss(x) (int) x.size()
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl;
#define ios cin.tie(0); ios_base::sync_with_stdio(0)
 
 
using namespace std;	

const int nax = 1e5 + 11;

int n, k;
ll sum;
int a[nax];
multiset <int> secik;

int main() {
	scanf("%d %d", &n, &k);
	sum = n;
	k = n - k;
	FOR(i, 1, n) {
		scanf("%d", &a[i]);
		if(i > 1)
			secik.insert(a[i] - a[i - 1] - 1);
	}
	while(k--) {
		sum += *secik.begin();
		secik.erase(secik.begin());
	}
	printf("%lld\n", sum);
	
	
	return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:27: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:31: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...