1763B - Incinerate - CodeForces Solution


binary search brute force data structures implementation math sortings *1200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
        //Allias//
    using namespace std;
    typedef long long int lli;
    typedef double dbl;
        //Macros//
    #define pb push_back
    // #define pop pop_back
    #define pf push_front
    #define popf pop_front
    #define vec vector <int>
    #define vll vector <lli>
    #define lb(p,n) lower_bound(p.begin(),p.end(),n)
    #define ub(p,n) upper_bound(p.begin(),p.end(),n)
     #define prqu priority_queue<lli, vector<lli>, greater<lli>>
    #define sqr(r) r * r 
    #define Nc2(n) (n) * ((n)-1)/2 
    #define frl(x,n) for(lli i = x; i < n; i++)
    #define loop(n) for(lli i = 0; i < n; i++)
    #define min(a,b) ((a)<(b)?(a):(b))
    #define max(a,b) ((a)>(b)?(a):(b))
    #define mp(x,y)make_pair(x,y)
    const int N = 1e7;
    #define lcm( a ,b) ((lli)a*b/__gcd(a,b))
    #define setbit(x,i) (x&(1<<i))
    #define totbit(x) ((lli)log2(x)+1)
    #define deb(x) cout << #x << "=" << x<<endl 
        //Constants
    constexpr lli M = 1e9+7;
    constexpr lli inf = 2e18;
     template<typename T> void print_pq(T&q)
      {
        while(q.size()!=0)
        {cout<<q.top()<<" ";
          q.pop();}
        cout<<endl;
      }
      bool sortbysecdesc(const pair<int,int> &a,const pair<int,int> &b)
    {
       return a.second>b.second;
    }
void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    vector<int> p(n);
    vector<pair<int,int>>h2(n);
    vector<int>mini(n);
    int dmg=k;
    loop(n)
    {
     cin>>h[i];
    }
    int mn=INT16_MAX;
    loop(n){
    cin>>p[i];
    }
    loop(n)
    {h2[i]=mp(h[i],p[i]);}
    sort(h2.begin(),h2.end());
    mini[n-1]=h2[n-1].second;
    for (int i=n-2; i>=0;i--)
        {
            mini[i]=min(h2[i].second,mini[i+1]);
        }
       int i=0;
    for(;i<n;)
        {
            
        if(h2[i].first-(dmg) >0 )
            
            {k=k-mini[i];

            dmg=dmg+k;

            }
            else{i++;}
            
            if(k<=0 ){break;}
            
        }

    

    if(h2[n-1].first<=dmg){cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}

    
   
      
}
int main()
{	
 ios_base::sync_with_stdio(true);
    cin.tie(0); cout.tie(0);
    int t;
    cin>>t;
while(t--)
{
    solve();
}
return 0;
}


Comments

Submit
0 Comments
More Questions

507B - Amr and Pins
379A - New Year Candles
1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns
1374C - Move Brackets
1476A - K-divisible Sum
1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm