답안 #843155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
843155 2023-09-03T18:21:48 Z Mr_Husanboy Stove (JOI18_stove) C++17
100 / 100
18 ms 2352 KB
#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

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);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 14 ms 2272 KB Output is correct
17 Correct 14 ms 2272 KB Output is correct
18 Correct 18 ms 2272 KB Output is correct
19 Correct 15 ms 2272 KB Output is correct
20 Correct 15 ms 2272 KB Output is correct
21 Correct 15 ms 2352 KB Output is correct
22 Correct 14 ms 2268 KB Output is correct
23 Correct 14 ms 2272 KB Output is correct
24 Correct 14 ms 2272 KB Output is correct