답안 #632936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632936 2022-08-21T09:02:04 Z Cyber_Wolf Stove (JOI18_stove) C++14
100 / 100
54 ms 2828 KB
//Contest: JOI '18
//Problem: Stove
//Link: https://oj.uz/problem/view/JOI18_stove

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")

using namespace std;
using namespace __gnu_pbds;

#define lg long long
#define ordered_set	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);
#define endl \n
#define lbound(x, y) lower_bound(x.begin(), x.end(), y) 
#define ubound(x, y) upper_bound(x.begin(), x.end(), y) 
#define sortasc(v) sort(v.begin(), v.end())	
#define sortdesc(v) sort(v.rbegin(), v.rend())	
#define custom_array(a,l, r) int _##a[r-l+1]; int*a=_##a-l;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const lg MOD = 1e9+7, N = 2e5+5, M = 1e7+1, SZ = 1e3+1;
/*
bitset<N> primes;
lg pwrs[N], inv[N];

lg fast_power(lg n, lg k)
{
	if(!k)	return 1;
	if(k&1)	return (fast_power(n, k-1)*n)%MOD;
	lg x = fast_power(n, k/2)%MOD;
	return (x*x)%MOD;
}

void sieve()
{
	primes.set();
	primes[0] = primes[1] = 0;
	for(lg i = 2; i < N; i++)
	{
		if(!primes[i])	continue;
		for(lg j = i*i; j < N; j += i)
		{
			primes[j] = 0;
		}
	}
	return;
}

struct matrix
{
	vector<vector<lg>> con = vector<vector<lg>> (SZ, vector<lg> (SZ));
	matrix operator *(const matrix& a)
	{
		matrix product;
		for(int i = 0; i < (lg)con.size(); i++)
		{
			for(int j = 0; j < (lg)a.con[0].size(); j++)
			{
				for(int k = 0; k < (lg)a.con.size(); k++)
				{
					product.con[i][j] = (product.con[i][j]+(con[i][k]*a.con[k][j])%MOD)%MOD; 
				}
			}
		}
		return product;
	}
};

void preprocess(lg x)
{
	inv[2e5] = fast_power(x, MOD-2);
	for(int i = 2e5-1; i > 1; i--)
	{
		inv[i] = (inv[i+1]*i)%MOD;
	}
	pwrs[0] = 1;
	for(int i = 1; i <= 2e5; i++)
	{
		pwrs[i] = (pwrs[i]*i)%MOD;
	}
	return;
}

*/

int main()
{
	lg n, k;
	cin >> n >> k;
	vector<lg> time(n), diff(n-1);
	for(auto&it: time)	cin >> it;
	for(int i = 1; i < n; i++)
	{
		diff[i-1] = time[i]-time[i-1]-1;
	}
	sort(diff.begin(), diff.end());
	lg sum = 0;
	for(int i = 0; i < n-k; i++)
	{
		sum += diff[i];
	}
	cout << n+sum << '\n';
	
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 312 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 312 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 49 ms 2828 KB Output is correct
17 Correct 48 ms 2764 KB Output is correct
18 Correct 43 ms 2744 KB Output is correct
19 Correct 45 ms 2820 KB Output is correct
20 Correct 54 ms 2752 KB Output is correct
21 Correct 48 ms 2756 KB Output is correct
22 Correct 43 ms 2828 KB Output is correct
23 Correct 46 ms 2764 KB Output is correct
24 Correct 47 ms 2740 KB Output is correct