Блог пользователя liveoverflow

Автор liveoverflow, история, 5 лет назад, По-английски

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[3]; cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
if(a[0]+a[1]>=a[2]){
   LL ans = a[2] + (a[0]+a[1]-a[2])/2;
   cout<<ans;
 }
else {
   LL ans = a[1] + min(a[0],a[2]-a[1]);
   cout<<ans;
 }
cout<<"\n";
}
}

~~~~~

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If you want somewhere (else) to submit:

https://codeforces.net/contest/1263/problem/A