답안 #164797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164797 2019-11-23T12:09:38 Z cbertram Stove (JOI18_stove) C++14
100 / 100
89 ms 2420 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)

int main() {
  int N, K;
  cin >> N;
  cin >> K;
  vi gs(N);
  rep(n,0,N) cin >> gs[n];
  sort(all(gs));
  vi gaps(0);
  rep(n,0,N-1) {
    if(gs[n]+1 < gs[n+1])
      gaps.push_back(gs[n+1]-gs[n]-1);
  }
  sort(all(gaps), greater<>());
  int ontime = N == 1 ? 1 : gs[N-1]-gs[0]+1;
  for(int k = 0; k < K-1 && k < (int)gaps.size(); k++) ontime -= gaps[k];
  cout << ontime << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 86 ms 2404 KB Output is correct
17 Correct 85 ms 2292 KB Output is correct
18 Correct 89 ms 2276 KB Output is correct
19 Correct 85 ms 2420 KB Output is correct
20 Correct 86 ms 2292 KB Output is correct
21 Correct 86 ms 2292 KB Output is correct
22 Correct 84 ms 2292 KB Output is correct
23 Correct 85 ms 2292 KB Output is correct
24 Correct 87 ms 2292 KB Output is correct