Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
959 B
8
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
int main()
{     
      int n,i,j,k,a;
      cin>>n;
      int h[n+3],e[n+3];
      vector<pair<int,int> >v;
      vector<int>ans;
      multiset<int,greater<int> >s;
      for(i=1;i<=n;i++){cin>>h[i];}
      for(i=1;i<=n;i++){cin>>e[i];v.push_back({h[i],e[i]});}
      cin>>k;
      sort(v.begin(), v.end());
      i=0;
      while(1){
            if(i>=n){break;}
            while(v[i].f<=k && i<n){
                  s.insert(v[i].s);
                  i++;
            }
            if(s.size()==0){break;} 
            a=*s.begin();
            s.erase(s.begin());
            k+=a;
            ans.push_back(k);
      }
      while(s.size()>0){
            a=*s.begin();
            s.erase(s.begin());
            k+=a;
            ans.push_back(k);
      }
      cout<<ans.size()<<" ";
      for(i=0;i<ans.size();i++){cout<<ans[i]<<" ";}cout<<"\n";
}