1217A - Creating a Character - CodeForces Solution


binary search math *1300

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#define pp pair<long long, long long>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define mini ll, vector<ll>, greater<ll>
using namespace std;

int main(int argc, char const *argv[])
{
  ll t;
  cin >> t;
  while (t--)
  {
    ll a, b, c;
    cin >> a >> b >> c;
   
  ll i=0;ll j=c;
    ll ans = -1;
    while (i<=j)
    {
      ll mid=(i+j)/2;
      if(a+mid>(b+(c-mid)))
      {
        ans=mid;
        j=mid-1;
      }
      else{
       i=mid+1;
      }

    }
    if(ans==-1)
    {
      if(a+c>b)
      {
        cout<<1;
      }
      else{
        cout<<0;
      }
    }
    else{
      cout<<c-ans+1;
    }
    cout << endl;
  }
  return 0;
}


Comments

Submit
0 Comments
More Questions

Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses