[Div 3 Starters 7]
(MAXSWT Problem - CodeChef)
here is my solution to the problem (link above)
I got Wrong Answer Can Someone help where i made mistake
Blockquote
#include<bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
//---------------------------------------
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//---------------------------------------
int t;
cin>>t;
while(t--)
{
long long int n,d;
cin>>n>>d;
vector <long long int> pi(n);
vector <long long int> si(n);
for (int i = 0; i < n; ++i)
{
cin>> pi[i];
}
for (int i = 0; i < n; ++i)
{
cin>> si[i];
}
unordered_map <long long int ,long long int> price;
for(int i = 0;i<n;i++)
{
//cout<<si[i]<<' '<<pi[i]<<endl;
price.insert( { si[i] , pi[i] } ) ;
}
//cout<<"--------------\n";
priority_queue <long long int> pq;
for(int i = 0;i<n;i++)
{
pq.push( si[i] );
}
long long int sweet = 0;
int c = 0;
while(!pq.empty() )
{
if( price[pq.top()] <= d)
{
sweet += pq.top();
d -= price[pq.top()];
pq.pop(); c++;
if(c == 2)
break;
}
else
{
pq.pop();
}
}
cout<<sweet<<endl;
}
return 0;
}
Blockquote