답안 #284362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284362 2020-08-27T09:21:02 Z ronnith Stove (JOI18_stove) C++14
100 / 100
32 ms 6256 KB
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	int n,k;
	cin>>n>>k;
	v<p<int,int>> hv;
	int st;
	int l=0;
	int mc=n;
	rep(i,0,n){
		cin>>st;
		hv.pb(mk(st,1));
		hv.pb(mk(st+1,0));
		l+=2;
	}
	sort(all(hv));
	vi gap;
	int ans=0;
	rep(i,1,l){
		if(hv[i].s==0){
			ans+=hv[i].f-hv[i-1].f;
		}
		else{
			gap.pb(hv[i].f-hv[i-1].f);
		}
	}
	sort(all(gap));
	int h=0;
	while(mc>k){
		ans+=gap[h];
		h++;
		mc--;
	}
	cout<<ans<<ln;
}

signed main(){
	boost_io;
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 640 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 1 ms 640 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 640 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 1 ms 640 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 29 ms 6248 KB Output is correct
17 Correct 29 ms 6256 KB Output is correct
18 Correct 29 ms 6256 KB Output is correct
19 Correct 32 ms 6256 KB Output is correct
20 Correct 29 ms 6256 KB Output is correct
21 Correct 29 ms 6248 KB Output is correct
22 Correct 30 ms 6256 KB Output is correct
23 Correct 30 ms 6256 KB Output is correct
24 Correct 30 ms 6244 KB Output is correct