답안 #137567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137567 2019-07-28T06:37:10 Z 윤교준(#3280) Coins (BOI06_coins) C++14
100 / 100
116 ms 6404 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmin(a,b) (a)=min((a),(b))
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXN = 500055;

ll D[MAXN];
int A[MAXN];
bitset<MAXN> B;

ll AnsC = 1;
int N, K, Ans;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> N >> K;
	for(int i = 1, c; i <= N; i++) {
		cin >> A[i] >> c;
		B[i] = !c;
	}
	fill(D+1, D+N+1, INFLL);
	for(int i = 1, k; i <= N; i++) if(B[i]) {
		ll t = i == N ? INFLL : A[i+1]-A[i];
		for(k = 1; k < N && D[k-1] <= t; k++);
		for(; k; k--) if(D[k-1] < t)
			upmin(D[k], D[k-1] + A[i]);
	}

	for(int i = 1; i <= N; i++) if(D[i] < K) {
		Ans = i;
		AnsC = D[i];
	}

	cout << Ans << endl << K-AnsC << endl;
	return 0;
}
# 결과 실행 시간 메모리 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 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 116 ms 6404 KB Output is correct
8 Correct 108 ms 6264 KB Output is correct
9 Correct 115 ms 6300 KB Output is correct
10 Correct 115 ms 6224 KB Output is correct