Source Code
#include <iostream>
#include<map>
#include<algorithm>
using namespace std ;

int main ()
{
  int n,s , temp , cnt = 0;
  cin>>n>>s;
  int t[n];
  for(int i =0 ; i<n;i++)cin>>t[i];
  map  <int , int> r;
  for(int i =0 ; i<n;i++)
  {
    cin>>temp;
    r[t[i]]=temp;
  }
  sort(t,t+n);
for(int i=0;s-t[i]>0 &&n!=0;i++)
{
  cnt ++;
  n--;
  s-=t[i];
  if(s==0)break;
  s+=r[t[i]];

}
cout<<cnt;
}
Copy
Wheatly's portals - Hard version Tala_Ibraheem
GNU G++17
3 ms
668 KB
Wrong Answer