1860B - Fancy Coins - CodeForces Solution


binary search greedy math

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_multiset;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;


#pragma GCC optimize("Ofast")  
//#pragma GCC target("avx,avx2,fma") 
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("-O2")

#define all(a)             (a).begin(), (a).end()
#define ll                 long long
#define fi                 first
#define se                 second
#define pb                 push_back
#define pob                pop_back
#define bb                 begin()
#define ee                 end()
#define endll              '\n'

#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define vi              vector<int>
#define vll             vector<long long int>
#define vii             vector<pii>
#define vpll            vector<pll>
 
#define inf               (1ll<<30ll)-1ll
#define llinf             (1ll<<62ll)-1ll

#define mod                1000000007
#define n_size             200005
#define g_size             20000005
#define eps                1e-9

const double PI=acos(-1);

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 way Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

vi v,value;

inline void solve(){

    ll n,m,t,res;

    ll l,r,mid;

    ll maxi=-inf,mini=inf,count=0;

    ll i,j,k;

    bool flag;

    ll a1,ak;

    cin>>m>>k>>a1>>ak;

    ll need = m%k;

    a1=a1-need;
    m=m-need;

    if(a1<0){
        count-=a1;
        a1=0;
    }

    m=m/k;

    m=m-min(ak,m);
    m=m-min(a1/k,m);

    count+=m;

    cout<<count<<endl;


 

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    //cout<<fixed<<setprecision(11);


    int T=1;
    cin>>T;

    while(T--) solve();
    
    
}


Comments

Submit
0 Comments
More Questions

780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack