Algorithm


A. Piles With Stones
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a beautiful garden of stones in Innopolis.

Its most beautiful place is the n piles with stones numbered from 11 to n.

EJOI participants have visited this place twice.

When they first visited it, the number of stones in piles was x1,x2,,xn�1,�2,…,��, correspondingly. One of the participants wrote down this sequence in a notebook.

They visited it again the following day, and the number of stones in piles was equal to y1,y2,,yn�1,�2,…,��. One of the participants also wrote it down in a notebook.

It is well known that every member of the EJOI jury during the night either sits in the room 108108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.

Participants want to know whether their notes can be correct or they are sure to have made a mistake.

Input

The first line of the input file contains a single integer n, the number of piles with stones in the garden (1n501≤�≤50).

The second line contains n integers separated by spaces x1,x2,,xn�1,�2,…,��, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0xi10000≤��≤1000).

The third line contains n integers separated by spaces y1,y2,,yn�1,�2,…,��, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0yi10000≤��≤1000).

Output

If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).

Examples
input
Copy
5
1 2 3 4 5
2 1 4 3 5
output
Copy
Yes
input
Copy
5
1 1 1 1 1
1 0 1 0 1
output
Copy
Yes
input
Copy
3
2 3 9
1 7 9
output
Copy
No
Note

In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.

In the second example, the jury took stones from the second and fourth piles.

It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int n, a[51], b[51], d[51];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i)
    scanf("%d", a + i);
  for(int i = 0; i < n; ++i)
    scanf("%d", b + i);
  for(int i = 0; i < n; ++i)
    d[i] = a[i] - b[i];

  for(int k = 0; k < 10000; ++k) {
    for(int i = 0; i < n; ++i) {
      if(d[i] <= 0)
        continue;
      for(int j = 0; j < n; ++j>
        if(d[j] < 0 && d[i] > 0)
          d[i] += d[j], d[j] = 0;
      break;
    }
  }

  bool ok = true;
  for(int i = 0; i < n; ++i)
    if(d[i] < 0)
      ok = false;

  if(ok)
    puts("Yes");
  else
    puts("No");

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
1 2 3 4 5
2 1 4 3 5

Output

x
+
cmd
Yes
Advertisements

Demonstration


Codeforces Solution-A. Piles With Stones-Solution in C, C++, Java, Python,Piles With Stones,Codeforces Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+