fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define MOD 1000000007
  6. double pi = acos(-1);
  7. void fast() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
  8.  
  9. unsigned long long modex(unsigned long long a, unsigned long long b, unsigned long long m) {
  10. if(b == 0) return 1;
  11. unsigned long long x = modex(a, b/2, m)%m;
  12. x = (x*x)%m;
  13. if(b % 2) x *= a;
  14. return x%m;
  15. }
  16. unsigned long long modinv(unsigned long long b) { return modex(b, MOD - 2, MOD); }
  17.  
  18. int main() {
  19. fast();
  20. //freopen("func.in", "r", stdin);
  21. // freopen("output.out", "w", stdout);
  22. int t;
  23. t = 1;
  24. cin >> t;
  25.  
  26.  
  27. while(t --) {
  28. int n;
  29. cin >> n;
  30.  
  31. vector <long long> v(n);
  32.  
  33. for(int i = 0; i < n; i ++) {
  34. cin >> v[i];
  35. }
  36.  
  37. long long lastMax = -1e10;
  38. long long lastSum = 0;
  39. string sol = "YES";
  40. for(int i = 0; i < n; i ++) {
  41. if(lastSum <= 0) {
  42. lastSum = v[i];
  43. lastMax = v[i];
  44. } else {
  45. lastSum += v[i];
  46. lastMax = max(v[i], lastMax);
  47. }
  48.  
  49. if(lastSum > lastMax) {
  50. sol = "NO";
  51. break;
  52. }
  53. }
  54.  
  55. lastMax = -1e10;
  56. lastSum = 0;
  57. for(int i = n-1; i >= 0; i --) {
  58. if(lastSum <= 0) {
  59. lastSum = v[i];
  60. lastMax = v[i];
  61. } else {
  62. lastSum += v[i];
  63. lastMax = max(v[i], lastMax);
  64. }
  65.  
  66. if(lastSum > lastMax) {
  67. sol = "NO";
  68. break;
  69. }
  70. }
  71.  
  72. cout << sol << "\n";
  73. }
  74. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
YES