Submission #843155

#TimeUsernameProblemLanguageResultExecution timeMemory
843155Mr_HusanboyStove (JOI18_stove)C++17
100 / 100
18 ms2352 KiB
#include <bits/stdc++.h>
using namespace std;



#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
	return a.size();
}

using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";


mt19937 mt(time(nullptr));
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;





void solve(){
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for(auto &u : a){
		cin >> u;
	}k --;

	vector<int> dif;
	for(int i = 0; i < n - 1; i ++){
		dif.push_back(a[i + 1] - a[i] - 1);
	}
	debug(dif);
	sort(all(dif), greater{});
	int sum = 0;
	for(int i = 0; i < k; i ++) sum += dif[i];
	cout << a[n - 1] - a[0] - sum + 1;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	auto start = chrono::high_resolution_clock::now();
	#ifndef LOCAL
	if(fileio.size()){
		freopen((fileio + ".in").c_str(), "r", stdin);
		freopen((fileio + ".out").c_str(), "w", stdout);
	}
	#endif
	int testcases = 1;
	#ifdef Tests
	cin >> testcases;
	#endif
	while(testcases --){
		solve();
		cout << '\n';
		#ifdef LOCAL
		cout << "_________________________" << endl;
		#endif
	}
	#ifdef LOCAL
	auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
	
	cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
	#endif
	return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:54:7: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   54 |  auto start = chrono::high_resolution_clock::now();
      |       ^~~~~
stove.cpp:57:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   freopen((fileio + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:58:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   freopen((fileio + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...