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>
#define ll long long
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A;
for (int i = 0; i < N; i++) {
int Ai;
cin >> Ai;
A.push_back(Ai);
}
vector<int> C;
for (int i = 0; i < N; i++) {
int Ci;
cin >> Ci;
C.push_back(Ci);
}
if (N <= 8) {
vector<int> perm;
for (int i = 1; i <= N; i++) {
perm.push_back(i);
}
vector<ll> ans (N,0);
do {
bool valid = true;
for (int i = 0; i < N; i++) {
if (A[i] != -1) {
//check if i is in position A[i]
if (perm[i]!=A[i]) {
valid = false;
break;
}
}
}
if (valid) {
vector<int> basket;
ll revenue = 0;
int max_t = 0;
for (int i = 0; i < N ; i++) {
if (perm[i] > max_t) {
max_t = perm[i];
revenue += C[perm[i]-1];
}
ans[i] = max(ans[i],revenue);
}
}
} while (next_permutation(perm.begin(),perm.end()));
for (int i = 0; i < N; i++) {
cout << ans[i];
if (i < N-1) {
cout << ' ';
} else {
cout << '\n';
}
}
} else {
ll revenue = 0;
for (auto p = C.rbegin(); p + 1 != C.rend(); p++) {
revenue += *p;
cout << revenue << ' ';
}
revenue += C.front();
cout << revenue << '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |