답안 #137561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137561 2019-07-28T06:32:02 Z 윤교준(#3280) Coins (BOI06_coins) C++14
90 / 100
116 ms 6392 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;
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 = min(N, k); 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 3 ms 376 KB Output is correct
2 Correct 5 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 376 KB Output is correct
7 Correct 112 ms 6264 KB Output is correct
8 Incorrect 107 ms 6392 KB Output isn't correct
9 Correct 116 ms 6392 KB Output is correct
10 Correct 116 ms 6392 KB Output is correct