public void solve() throws IOException {
    int n = nextInt();
    int m = nextInt();
    
    int total = 0;
    
    int[] cur = new int[n];
    int[] target = new int[n];
    for (int x = 0; x < n; x++) {
      cur[x] = nextInt();
      total += cur[x];
    }
    for (int x = 0; x < n; x++) {
      target[x] = nextInt();
      total -= cur[x];
    }
    
    List<Integer>[] edges = new List[n];
    for (int x = 0; x < n; x++) {
      edges[x] = new ArrayList<Integer>();
    }
   
    for (int x = 0; x < m; x++) {
      int p = nextInt();
      int q = nextInt();
      edges[p - 1].add(q - 1);
      edges[q - 1].add(p - 1);
    }
    
    if (total != 0) {
      System.out.println("NO");
      return;
    }
    
    for (int x = 0; x < n; x++) {
      if (target[x] > cur[x]) {
        int possible = 0;
        for (int neighbor : edges[x]) {
          possible += cur[neighbor];
        }
        if (possible < target[x] - cur[x]) {
          System.out.println("NO");
          return;
        }
      }
    }
  }