#include<iostream>                                                                                                                
#include<algorithm>                                                                                                               
using namespace std;                                                                                                              
                                                                                                                                   
int main(void) {                                                                                                                  
  int n, x, s = 0;                                                                                                                
  char p[1000];                                                                                                                   
  cin >> n;                                                                                                                       
  for (int i=0; i<n; i++) {                                                                                                       
    cin >> p[i] >> x;                                                                                                             
    if (p[i] == '(') {                                                                                                            
      s += x;                                                                                                                     
    } else {                                                                                                                      
      s -= x;                                                                                                                     
    }                                                                                                                             
    if (s < 0) {                                                                                                                  
      cout << "NO" << endl;                                                                                                       
      return 0;                                                                                                                   
    }                                                                                                                             
  }                                                                                                                               
  if (s == 0) {                                                                                                                   
    cout << "YES" << endl;                                                                                                        
  } else {                                                                                                                        
    cout << "NO" << endl;                                                                                                         
  }                                                                                                                                                                                                                                                     
}  


Measured memory_bytes: 3096