fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define int long long
  7. #define pb push_back
  8. #define all(x) (x).begin(),(x).end()
  9. #define fi first
  10. #define se second
  11.  
  12. int const MAXN=1e3+10;
  13. int const INF=1e18;
  14.  
  15. void open(){
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(NULL); cout.tie(NULL);
  18. // freopen(TASK".INP","r",stdin);
  19. // freopen(TASK".OUT","w",stdout);
  20. }
  21.  
  22. bool compareValue(pair<int,int>x,pair<int,int>y){
  23. return x.first<y.first;
  24. }
  25.  
  26. int n,ans,sumans;
  27. pair<int,int> s[MAXN];
  28.  
  29. signed main(){
  30. open();
  31. cin>>n;
  32.  
  33. for(int i=1;i<=n;i++){
  34. cin>>s[i].fi;
  35. }
  36.  
  37. for(int i=1;i<=n;i++){
  38. cin>>s[i].se;
  39. sumans+=s[i].se;
  40. }
  41.  
  42. sort(s+1,s+n+1,compareValue);
  43.  
  44. multiset<int> ccb={0};
  45.  
  46. for(int i=1;i<=n;i++){
  47. if(ccb.size()<s[i].fi){
  48. ccb.insert(s[i].se);
  49. ans+=s[i].se;
  50. }
  51. else{
  52. if(*ccb.begin()<=s[i].se){
  53. ans-=*ccb.begin();
  54. ccb.erase(ccb.begin());
  55. ccb.insert(s[i].se);
  56. ans+=s[i].se;
  57. }
  58. }
  59. }
  60.  
  61. cout<<sumans-ans;
  62. return 0;
  63. }
Success #stdin #stdout 0s 5336KB
stdin
Standard input is empty
stdout
Standard output is empty