답안 #683590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683590 2023-01-18T19:15:01 Z TimDee Stove (JOI18_stove) C++17
100 / 100
41 ms 6736 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")

#define forn(i,n) for(int i=0;i<n;++i)
#define pb(x) push_back(x)
#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pi pair<int,int>
#define f first
#define s second
#define int long long

const int inf = 1e18;
const int mod = 1e9+7;//998244353;
using ll = long long;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
		
	int n,k; cin>>n>>k;
	vii(a,n);
	int cnt=0;
	int ans=n;
	multiset<int> s;
	forn(i,n-1) s.insert(a[i+1]-a[i]-1);
	while (s.size()>=k) {
		ans+=*s.begin();
		s.erase(s.begin());
	}
	cout<<ans;

}

int32_t main() { 
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
   	//cin>>t;
    while(t--) solve();
    return 0;
}

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:31:17: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   31 |  while (s.size()>=k) {
      |                 ^
stove.cpp:27:6: warning: unused variable 'cnt' [-Wunused-variable]
   27 |  int cnt=0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 38 ms 6712 KB Output is correct
17 Correct 40 ms 6716 KB Output is correct
18 Correct 36 ms 6724 KB Output is correct
19 Correct 36 ms 6732 KB Output is correct
20 Correct 41 ms 6732 KB Output is correct
21 Correct 35 ms 6732 KB Output is correct
22 Correct 36 ms 6712 KB Output is correct
23 Correct 36 ms 6728 KB Output is correct
24 Correct 36 ms 6736 KB Output is correct