답안 #956138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956138 2024-04-01T07:12:16 Z manishjha91 Stove (JOI18_stove) C++17
100 / 100
20 ms 3364 KB
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using lld = long double;

// #ifndef ONLINE_JUDGE
// #include "E:\Personal\cpp_codes\debugalgo.h"
// #else
// #define debug(x)
// #endif
// 

void solve(int tc)
{
	ll n,k;
	cin>>n>>k;
	
	

	vector<ll> a(n);
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	
	sort(a.begin(),a.end());
	
	vector<ll> gap;
	
	for(int i=1; i<n; i++)
	{
		gap.push_back(a[i]-a[i-1]-1);
	}
	
	ll res = n;
	ll req = n;
	sort(gap.begin(),gap.end());
	
	for(int i=0; i<n-k; i++)
	{
		res+=gap[i];
	}
	
	cout<<res<<"\n";
	
}

int main()
{
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("Error.txt", "w", stderr);
// #endif

	int tt = 1;
	// cin >> tt;
	for(int tc=1; tc<=tt; tc++)
	{
		solve(tc);
	}
}

Compilation message

stove.cpp: In function 'void solve(int)':
stove.cpp:38:5: warning: unused variable 'req' [-Wunused-variable]
   38 |  ll req = n;
      |     ^~~
# 결과 실행 시간 메모리 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 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 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 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 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 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 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 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 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 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 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 17 ms 3292 KB Output is correct
17 Correct 16 ms 3292 KB Output is correct
18 Correct 17 ms 3288 KB Output is correct
19 Correct 16 ms 3292 KB Output is correct
20 Correct 16 ms 3364 KB Output is correct
21 Correct 16 ms 3292 KB Output is correct
22 Correct 20 ms 3292 KB Output is correct
23 Correct 19 ms 3292 KB Output is correct
24 Correct 16 ms 3288 KB Output is correct