loading...

Daily Coding Challenge #52

wingkwong profile image wkw ・2 min read

About

This is a series of Daily Coding Challenge. Each day I show a few solutions written in C++. The questions are from coding practice/contest sites such as HackerRank, LeetCode, Codeforces, Atcoder and etc.


/*
Codeforces Round #654 (Div. 2) - A. Magical Sticks
https://codeforces.com/contest/1371/problem/A
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    int n,t;
    cin >> t;
    while(t--){
        cin >> n;
        if(n%2==0) cout << n/2 << endl;
        else cout << (n/2)+1 << endl;
        // or cout << (n+1)/2 << endl;
    }
    return 0;
} 

/*
Codeforces Round #654 (Div. 2) - B. Magical Calendar
https://codeforces.com/contest/1371/problem/B
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    long long t,n,r,ans;
    cin >> t;
    while(t--){
        cin >> n >> r;
        if(n>r) ans=(r*(r+1))/2;
        else ans=((n*(n-1))/2)+1;
        cout<<ans<<endl;
    }
    return 0;
} 

/*
Codeforces Round #654 (Div. 2) - C. A Cookie for You
https://codeforces.com/contest/1371/problem/C
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    long long t,a,b,n,m;
    cin >> t;
    while(t--){
        cin >> a >> b >> n >> m;
        if(min(a,b)<m) cout << "No" << endl;
        else if(a+b<n+m) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
} 

The source code is available in corresponding repo below. Star and watch for timely updates!

GitHub logo wingkwong / leetcode

🏆 A Collection of my LeetCode Solutions with Explanations 🏆

GitHub logo wingkwong / hackerrank

🏆 A Collection of my HackerRank Solutions with Explanations 🏆

GitHub logo wingkwong / codeforces

🏆 A Collection of my Codeforces Solutions with Explanations 🏆

GitHub logo wingkwong / atcoder

🏆 A Collection of my AtCoder Solutions with Explanations 🏆

Discussion

pic
Editor guide