MAXSWT - Editorial

please check where i am going wrong

my code–>

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define endl ‘\n’

bool cmp(pair<int,int> a,pair<int, int> b)
{
if(a.ss==b.ss)
return a.ff<b.ff;
return a.ss>b.ss;
}

ll solve()
{
vector<pair<int,int>> v;
ll n,d,val;
cin>>n>>d;
int i=0;
for(i=0;i<n;i++)
cin>>v[i].ff;
for(i=0;i<n;i++)
cin>>v[i].ss;
sort(v.begin(),v.end(),cmp);
ll max_sweet=0,price=0,cnt=0;
i=0;
while(i<n&&cnt<2)
{
if(price+v[i].ff<=d)
{
cnt++;
max_sweet+=v[i].ss;
price+=v[i].ff;
}
i++;
}
return max_sweet;
}

int main()
{
fastio;
ll tc = 1;
cin >> tc;
for (ll t = 1; t <= tc; t++)
{
// cout << “Case #” << t << ": ";
cout<<solve()<<endl;
//solve();
}
}

very good editorial.
Good implementation of set .
I know how to solve this question but not able to implement it.
Thanks for such a editorial.

please lemme know why this approach is incorrect