Codeforces 1294A. Collecting Coins Solution

  1. ///**********ALLAH IS ALMIGHTY************///
  2. ///AH Tonmoy
  3. ///Department of CSE
  4. ///Islamic University,Bangladesh
  5. #include <iostream>
  6. #include<algorithm>
  7. using namespace std;
  8. int main()
  9. {
  10. long long int test,n1,n2,value,a,b,c,n,v,ar[10]= {0},j;
  11. cin>>test;
  12. while(test--)
  13. {
  14. for(j=0; j<3; j++)
  15. {
  16. cin>>ar[j];
  17. }
  18. sort(ar,ar+3);
  19. cin>>n;
  20. n1=ar[2]-ar[0];
  21. n2=ar[2]-ar[1];
  22. value=n-(n1+n2);
  23. if(value>=0)
  24. {
  25. if(value%3==0)
  26. {
  27. v=value/3;
  28. a=ar[0]+n1+v;
  29. b=ar[1]+n2+v;
  30. c=ar[2]+v;
  31. if(a==b&&b==c)
  32. cout<<"YES"<<endl;
  33. else
  34. cout<<"NO"<<endl;
  35. }
  36. else
  37. cout<<"NO"<<endl;
  38.  
  39. }
  40. else
  41. cout<<"NO"<<endl;
  42. }
  43. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.