Submission #146927

#TimeUsernameProblemLanguageResultExecution timeMemory
146927GodTeStove (JOI18_stove)C++14
100 / 100
29 ms1524 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

// #define TT() printf("%.4f sec\n", (double) clock() / CLOCKS_PER_SEC )
#define Fi first
#define Se second
#define rep(i, n) for(ll i=0;i<n;i++)
#define repp(i, n) for(ll i=1;i<=n;i++)

#define INF 1987654321
#define IINF 987654321987654321

int n,k; vector<int> v,v1;

int main(){
	scanf("%d%d",&n,&k);
	repp(i,n){
		int x; scanf("%d",&x); v.push_back(x);
	}
	int ans = v[n-1]-v[0]+1;
	rep(i,n-1) v1.push_back(v[i+1]-v[i]-1);
	sort(v1.begin(),v1.end(),greater<int>());
	rep(i,min(n-1,k-1)) ans -= v1[i];
	printf("%d\n",ans);

	return 0;
} 

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:20: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:22:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x); v.push_back(x);
          ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...