답안 #652708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
652708 2022-10-24T02:07:07 Z _HDH Stove (JOI18_stove) C++11
100 / 100
37 ms 6328 KB
#include <bits/stdc++.h>

#ifdef LOCAL
#include <debug.h>
#else
#define debug(...) 1001
#endif

using namespace std;
#define all(x) x.begin(), x.end()
#define st first
#define nd second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define file "TEMPLATE"

typedef long long ll;
typedef pair<int, int> ii;
typedef array<int, 3> iii;
typedef vector<int> vi;
typedef vector<ll> vl;

bool const SINGLE_TEST = 1;

int const N = 1e5 + 1;

void solve(){
	int n, k; cin >> n >> k;
	
	int arr[N] = {};
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	
	multiset<int> s;
	for (int i = 2; i <= n; i++){
		s.insert(arr[i] - arr[i - 1] - 1);
		if (s.size() > k - 1) s.erase(s.begin());
	}
	
	ll ans = arr[n] + 1 - arr[1];
	for (auto x: s)
		ans -= x;
	cout << ans;
}

int main(){
	ios_base::sync_with_stdio(0);//      the
	cin.tie(0);cout.tie(0);// 	    magical lines	
	// freopen(file".inp", "r", stdin);
	// freopen(file".out", "w", stdout);
	int t;
	if (SINGLE_TEST) t = 1;
	else cin >> t;
	while (t--) solve();
	return 0;
}//it's coding time!

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:42:16: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |   if (s.size() > k - 1) s.erase(s.begin());
      |       ~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 704 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 712 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 704 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 712 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 728 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 740 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 2 ms 844 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 704 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 712 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 728 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 740 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 2 ms 844 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 15 ms 1620 KB Output is correct
17 Correct 20 ms 1620 KB Output is correct
18 Correct 16 ms 1716 KB Output is correct
19 Correct 19 ms 2104 KB Output is correct
20 Correct 32 ms 3912 KB Output is correct
21 Correct 36 ms 5880 KB Output is correct
22 Correct 36 ms 6328 KB Output is correct
23 Correct 36 ms 6232 KB Output is correct
24 Correct 37 ms 6284 KB Output is correct