Ashvant and his girlfriends...


Problem Statement :

https://www.codechef.com/KOPC2016/problems/K16F

Problem Solution :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    long long int a,b,c,ans1,ans2,ans;
    while(t--)
    {
      cin>>a>>b>>c;
      ans1=ans2=ans=0;
      ans1=(a/3)+(b/3)+(c/3);
      ans1+=(min(min(a%3,b%3),c%3));
      if(a%3==0&&a!=0){
          ans2+=((a-3)/3);
          a=3;
      }
      else{
          ans2+=(a/3);
          a=a%3;
      }
      if(b%3==0&&b!=0){
          ans2+=((b-3)/3);
          b=3;
      }
      else{
          ans2+=(b/3);
          b=b%3;
      }
      if(c%3==0&&c!=0){
          ans2+=((c-3)/3);
          c=3;
      }
      else{
          ans2+=(c/3);
          c=c%3;
      }
      ans2+=(min(min(a,b),c));
      ans=max(ans1,ans2);
      cout<<ans<<endl;
    }
    return 0;
}

No comments:

Post a comment