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 <vector>
#include <iostream>
#include <set>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> arr(N), brr(N);
set<int> used;
for(int i = 0; i < N; i ++){
cin >> arr[i];
used.insert(arr[i]);
}
for(int i = 0; i < N; i ++){
cin >> brr[i];
}
int maxi = -1;
set<int> left;
for(int i = 1; i <= N; i ++){
if(used.find(i) == used.end())
left.insert(i);
}
vector<int> C(N);
for(int i = 0; i < N; i ++){
maxi = max(arr[i], maxi);
if(arr[i] != -1)continue;
if(left.lower_bound(maxi+1)!=left.end()){
arr[i] = *left.lower_bound(maxi+1);
left.erase(left.lower_bound(maxi+1));
}
else{
arr[i] = *left.begin();
left.erase(left.begin());
}
}
int c = 0;
maxi = -1;
for(int i = 0; i < N; i ++){
if(arr[i] > maxi){
c += brr[arr[i]-1];
maxi = arr[i];
}
C[i] = c;
}
for(int i : C){
cout << i << " ";
}
cout << endl;
return 0;
}
# | 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... |