Submission #832458

#TimeUsernameProblemLanguageResultExecution timeMemory
832458LiudasFruits (NOI22_fruits)C++17
0 / 100
310 ms28640 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...