# FINDSHOES - Editorial

Setter: Jeevan Jyot Singh
Tester: Ashley Khoo, Nishant Shah
Editorialist: Prakhar Kochar

Simple

None

# PROBLEM:

Chef has N friends. Chef promised that he would gift a pair of shoes (consisting of one left shoe and one right shoe) to each of his N friends. Chef was about to go to the marketplace to buy shoes, but he suddenly remembers that he already had M left shoes.

What is the minimum number of extra shoes that Chef will have to buy to ensure that he is able to gift a pair of shoes to each of his N friends?

# EXPLANATION:

Given that Chef needs to buy N pair of shoes i.e. N left shoes and N right shoes.

For left shoes
Since Chef already has M left shoes, following 2 cases are possible

• M \geq N; In this case, Chef doesn’t need to buy any left shoe as he already has the required quantity.

• M \lt N; In this case, Chef will need to buy N-M more left shoes to gift a total of N left shoes.

For right shoes
Chef will need to buy all the required N right shoes since there are no right shoes already present with him.

Therefore, minimum number of extra shoes that Chef will have to buy to ensure that he is able to gift a pair of shoes to each of his N friends is given by following equation

Minimum number of shoes Chef needs to buy are = N + max(0, N-M)

Examples

N = 5, M = 4;

Minimum number of shoes Chef needs to buy are = 5 + max(0, 1) = 6

N = 5, M = 6;

Minimum number of shoes Chef needs to buy are = 5 + max(0, -1) = 5

# TIME COMPLEXITY:

O(1) for each test case.

# SOLUTION:

Tester-1's Solution
``````// Super Idol的笑容
//    都没你的甜
//  八月正午的阳光
//    都没你耀眼
//  热爱105°C的你
// 滴滴清纯的蒸馏水

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

#define int long long
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int a,b;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int TC;
cin>>TC;
while (TC--){
cin>>a>>b;
cout<<a+max(0LL,a-b)<<endl;
}
}
``````
Tester-2's Solution
``````#include <bits/stdc++.h>
using namespace std;

/*
---------Input Checker(ref : https://pastebin.com/Vk8tczPu )-----------
*/

long long readInt(long long l, long long r, char endd)
{
long long x = 0;
int cnt = 0;
int fi = -1;
bool is_neg = false;
while (true)
{
char g = getchar();
if (g == '-')
{
assert(fi == -1);
is_neg = true;
continue;
}
if ('0' <= g && g <= '9')
{
x *= 10;
x += g - '0';
if (cnt == 0)
{
fi = g - '0';
}
cnt++;
assert(fi != 0 || cnt == 1);
assert(fi != 0 || is_neg == false);

assert(!(cnt > 19 || (cnt == 19 && fi > 1)));
}
else if (g == endd)
{
if (is_neg)
{
x = -x;
}

if (!(l <= x && x <= r))
{
cerr << l << ' ' << r << ' ' << x << '\n';
assert(1 == 0);
}

return x;
}
else
{
assert(false);
}
}
}
string readString(int l, int r, char endd)
{
string ret = "";
int cnt = 0;
while (true)
{
char g = getchar();
assert(g != -1);
if (g == endd)
{
break;
}
cnt++;
ret += g;
}
assert(l <= cnt && cnt <= r);
return ret;
}
long long readIntSp(long long l, long long r)
{
}
long long readIntLn(long long l, long long r)
{
}
{
}
{
}

/*
-------------Main code starts here------------------------
*/

// Note here all the constants from constraints
const int MAX_T = 100;
const int MAX_VAL = 100;

// vars
int opt_a = 0;
int opt_b = 0;

void solve()
{
int n, m;

int answer = n + n - min(m, n);

if (m < n)
opt_a++;
else
opt_b++;

}

signed main()
{
int t;

for (int i = 1; i <= t; i++)
{
solve();
}

// Make sure there are no extra characters at the end of input
assert(getchar() == -1);
cerr << "SUCCESS\n";

// Some important parameters which can help identify weakness in testdata
cerr << "Tests : " << t << '\n';
cerr << "Option  A : " << opt_a << '\n';
cerr << "Option  B : " << opt_b << '\n';
}
``````
Editorialist's Solution
``````/*prakhar_87*/
#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define inf INT_MAX
#define mod 998244353

void f() {
int n, m;
cin >> n >> m;
cout << n + max(0ll, n - m) << "\n";
}

int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) f();
}
``````