This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> X(N), L(N);
for (int &xi : X) {
cin >> xi;
}
for (int &li : L) {
cin >> li;
}
vector<int> idx(N);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](int i, int j) { return (L[i] == L[j] ? X[i] < X[j] : L[i] < L[j]); });
int64_t INF = INT_MAX;
vector<vector<int64_t>> dp(N+1, vector<int64_t>(N+1, INF));
dp[0][0] = 0;
dp[0][1] = X[idx[0]];
for (int i = 1;i < N; ++i) {
dp[i][0] = 0;
for (int j = 1;j <= N; ++j) {
dp[i][j] = dp[i-1][j];
if (dp[i-1][j-1] <= L[idx[i]]) {
dp[i][j] = min(dp[i][j], dp[i-1][j-1] + X[idx[i]]);
}
}
}
int ans = 0;
while (ans+1 <= N && dp[N-1][ans+1] != INF) {
ans += 1;
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |