Submission #137558

# Submission time Handle Problem Language Result Execution time Memory
137558 2019-07-28T06:30:48 Z 윤교준(#3280) Coins (BOI06_coins) C++14
60 / 100
1000 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; i <= N; i++) if(B[i]) {
		ll t = i == N ? INFLL : A[i+1]-A[i];
		for(int k = N; 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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 296 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 Execution timed out 1030 ms 6292 KB Time limit exceeded
8 Incorrect 108 ms 6264 KB Output isn't correct
9 Execution timed out 1018 ms 6392 KB Time limit exceeded
10 Execution timed out 1052 ms 6264 KB Time limit exceeded