fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n, addi;
  7. cin>>n>>addi;
  8. vector<int> capacity(n), rocks(n);
  9. for(int i=0;i<n;i++)cin>>capacity[i];
  10. for(int i=0;i<n;i++)cin>>rocks[i];
  11. priority_queue<int, vector<int>, greater<int>> pq;
  12. for(int i=0;i<rocks.size();i++){
  13. if(capacity[i]-rocks[i]!=0)pq.push(capacity[i]-rocks[i]);
  14. }
  15. // while(!pq.empty()){
  16. // cout<<pq.top()<<endl;
  17. // pq.pop();
  18. // }
  19. while(!pq.empty()){
  20. if(pq.top()<=addi){
  21. addi-=pq.top();
  22. pq.pop();
  23. }
  24. else{
  25. break;
  26. }
  27. }
  28. while(!pq.empty()){
  29. cout<<pq.top()<<endl;
  30. pq.pop();
  31. }
  32. cout<<pq.size()<<endl;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5432KB
stdin
4 2
2 3 4 5
1 2 4 4
stdout
1
0