답안 #930258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930258 2024-02-19T08:13:49 Z Xiaoyang Stove (JOI18_stove) C++17
100 / 100
17 ms 2984 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 1ll<<60
#define rep(i,a,b) for (ll i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
#define endl "\n"
void inc(ll &a,ll b) {a=(a+b)%mod;}
void dec(ll &a,ll b) {a=(a-b+mod)%mod;}
int prod(ll a,ll b) {return ll(a)*ll(b)%mod;}
int lowbit(ll x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}



const ll maxn=111111;
ll a[maxn],diff[maxn];

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,k;cin>>n>>k;
	rep(i,1,n+1)cin>>a[i];
	//spit into <=k intevals 
	//must contain the N points
	//a[] is sorted
	ll ans=n;
	rep(i,2,n+1){
		diff[i]=a[i]-(a[i-1]+1);
	}
	sort(diff+2,diff+n+1);
	ll p=2;
	while(n>k){
		ans+=diff[p];
		p++;
		n--;
	}
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 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 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 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 476 KB Output is correct
16 Correct 15 ms 2904 KB Output is correct
17 Correct 15 ms 2908 KB Output is correct
18 Correct 17 ms 2908 KB Output is correct
19 Correct 14 ms 2908 KB Output is correct
20 Correct 14 ms 2984 KB Output is correct
21 Correct 14 ms 2852 KB Output is correct
22 Correct 14 ms 2904 KB Output is correct
23 Correct 14 ms 2904 KB Output is correct
24 Correct 14 ms 2908 KB Output is correct