1468N - Waste Sorting - CodeForces Solution


greedy implementation *900

Please click on ads to support us..

C++ Code:

 #include<bits/stdc++.h>
using namespace std;
 
#define pr pair<int,int>
#define mp make_pair  
#define PI 3.141592653589793238462
#define Nmax 1e18
#define LMAO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout.precision(20),cout.setf(ios::fixed)
#define ll long long
#define lld long double
#define eb emplace_back
#define pb push_back
#define nl "\n"
const int M=1e9+7;
 
/*
const int N=1e7+1;
int spf[N]={0};
void createspf(){ 
    for(int i=2;i<N;i++){
        spf[i]=i;
    }
 
    for(int i=2;i*i<=N-1;i++){
        if(spf[i]==i){
            for(int j=i*i;j<=N-1;j+=i){
                if(spf[j]==j)
                spf[j]=i;
            }
        }
    }
 
}
*/
 
/*
const int N=1e5;
vector<bool> v(N+1,0);
vector<int> ans;
void crsieve(){
 
    for(int i=2;i<=N;i++){
        v[i]=true;
    }
 
    for(int j=2;j*j<=N;j++){
        if(v[j]){
            ans.eb(j);
            for(int i=j*j;i<=N;i+=j){
                v[i]=false;
            }
        }
    }
// doen with all primes till 100000
}
*/
 
 
ll int binexp(ll int x, ll int y,ll int mod){
    ll int res=1;
    while(y>0){
        if(y&1)
        res=(res*x)%mod;
        x=(x*x)%mod;
        y>>=1;
    }
 
return res;
}
 
 
const int N=1e6;
ll int fact[N+1];
ll int invfact[N+1];


void facto(){
    fact[0]=1;
for(int i=1;i<=N;i++){
fact[i]=( fact[i-1]*i)%M;
}
}
 
void invfacto(){
    // a-1 == a(p-2) %m-2
    invfact[0]=1;
   for(int i=1;i<=N;i++){
    invfact[i]= binexp(fact[i],M-2,M);
   }
 
}
 
void SOLVE(){
  int c1,c2,c3,a1,a2,a3,a4,a5;
  cin>>c1>>c2>>c3>>a1>>a2>>a3>>a4>>a5;
  bool flag=true;
    c1-=a1;c2-=a2;c3-=a3;
    int req1=0,req2=0;
    if(c1>=0 &&c2>=0 && c3>=0){
        // a4 a5
        req1= (c1+c3)-a4;
        if(req1>=0){
            if(a4>=c1){
                a4-=c1;
                c1=0;
                c3-=a4;
                if(c3>=0){
                    if(c3+c2<a5){
                        flag=false;
                    }
                }
                else{
                    flag=false;
                }
            }
            else{
                a4=0;
                req2=c2+c3-a5;
                if(req2<0){
                    flag=0;
                }
            }
        }
        else
        flag=false;
    }
    else
    flag=false;

    if(flag)
    cout<<"YES"<<nl;
    else
    cout<<"NO"<<nl;

}
 
int main(){
    LMAO;
    //createspf(); 
    //crsieve();    
    //facto();
    //invfacto();
    
    int T=1;//
    cin>>T; //activating multiple test cases;

    while(T--){
        SOLVE();
    }

 return 0;
}


Comments

Submit
0 Comments
More Questions

461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal
589. N-ary Tree Preorder Traversal
1299. Replace Elements with Greatest Element on Right Side
1768. Merge Strings Alternately
561. Array Partition I
1374. Generate a String With Characters That Have Odd Counts
1822. Sign of the Product of an Array
1464. Maximum Product of Two Elements in an Array
1323. Maximum 69 Number
832. Flipping an Image
1295. Find Numbers with Even Number of Digits
1704. Determine if String Halves Are Alike
1732. Find the Highest Altitude
709. To Lower Case
1688. Count of Matches in Tournament
1684. Count the Number of Consistent Strings
1588. Sum of All Odd Length Subarrays
1662. Check If Two String Arrays are Equivalent
1832. Check if the Sentence Is Pangram
1678. Goal Parser Interpretation
1389. Create Target Array in the Given Order
1313. Decompress Run-Length Encoded List