Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

Maximum number of pairwise decrements possible in three numbers

Revision en1, by liveoverflow, 2020-03-29 00:21:51

Given are the 3 non-negative integers a,b,c

In a single operation, we have to subtract 1 from two integers only if they don't become negative.

We have to find the maximum no of operations possible that we can do until the given operation is not possible.

constraints:1<=a,b,c<=10^18 , 1<=test-cases<=10^5

Example- (1,2,3) = (1,1,2) -> (1,0,1) -> (0,0,0) , ans is 3

(1,1,8) = (1,0,7) -> (0,0,6) , ans is 2

Any approach or proof will be highly helpful.

I have actually written a code that's working as far as I know, but I don't know if it's completely true,

Thanks ~~~~~

#include<bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define LL long long

int main(){
fastio;
int t; cin>>t;
while(t--){
LL a; cin>>a>>a>>a;
sort(a,a+3);
if(a+a>=a){
LL ans = a + (a+a-a)/2;
cout<<ans;
}
else {
LL ans = a + min(a,a-a);
cout<<ans;
}
cout<<"\n";
}
}

~~~~~ #### History

Revisions Rev. Lang. By When Δ Comment
en1 liveoverflow 2020-03-29 00:21:51 1155 Initial revision (published)