Codeforces Round 613 (Div. 2) 1285B - Just Eat It! Solution
Problem Link : https://codeforces.com/problemset/problem/1285/B
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long ;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t ;
- cin >> t ;
- while ( t-- ) {
- int n ;
- cin >> n ;
- ll a[n+1] , sum = 0 ;
- bool x = true , y = true ;
- for ( int i = 0 ; i < n ; i++ ) {
- cin >> a[i] ;
- sum += a[i] ;
- if (sum <=0 ){
- x = false ;
- }
- }
- sum = 0 ;
- for ( int i = n-1 ; i >= 0 ; i-- ) {
- sum += a[i] ;
- if (sum <=0 ){
- y = false ;
- }
- }
- if ( x == false || y == false )
- cout << "NO" << endl;
- else
- cout <<"YES"<<endl;
- }
- }
No comments