Codeforces Round 613 (Div. 2) 1285B - Just Eat It! Solution


 

 Problem Link  :  https://codeforces.com/problemset/problem/1285/B

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. using ll = long long ;
  10. int main() {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. int t ;
  14. cin >> t ;
  15. while ( t-- ) {
  16. int n ;
  17. cin >> n ;
  18. ll a[n+1] , sum = 0 ;
  19. bool x = true , y = true ;
  20. for ( int i = 0 ; i < n ; i++ ) {
  21. cin >> a[i] ;
  22. sum += a[i] ;
  23. if (sum <=0 ){
  24. x = false ;
  25. }
  26. }
  27. sum = 0 ;
  28. for ( int i = n-1 ; i >= 0 ; i-- ) {
  29. sum += a[i] ;
  30. if (sum <=0 ){
  31. y = false ;
  32. }
  33. }
  34. if ( x == false || y == false )
  35. cout << "NO" << endl;
  36. else
  37. cout <<"YES"<<endl;
  38. }
  39. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.