519C - A and B and Team Training - CodeForces Solution


greedy implementation math number theory *1300

Please click on ads to support us..

Python Code:

n,m=map(int,input().split())
ans=0
while (m>=2 and n>=1)or (m>=1 and n>=2) :
    ans+=1
    if(m>n):
        m-=2
        n-=1
    else:
        m-=1
        n-=2
print(ans)
    

C++ Code:

#include<bits/stdc++.h>
/*
author:- laksheya_0809
*/
using namespace std;

#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb push_back
#define ppb pop_back
#define vvi vector<vi>
#define vii vector<ii>
#define ln << '\n'
#define sz(x) (int)((x).size())
#define _for(s, n, upd) for(int i = s; i < n; i+=upd)
#define rep(i, s, n) for(int i = s; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define fill(x, y) memset(x, y, sizeof x) 
#define ump unordered_map
const int MOD = 1e9+7;

void sol() {
    int n, m; cin >> n >> m;
    int teams = 0;
    while(n > 0 && m > 0) {
        if(n > m) {
            n -= 2;
            m -= 1;
        } else {
            m -= 2;
            n -= 1;
        }
        if(n >= 0 && m >= 0)
            teams++;
    }
    cout << teams ln;
}



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) sol();
    return 0;
}


Comments

Submit
0 Comments
More Questions

Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II