fork download
  1. /* package whatever; // don't place package name! */
  2. import java.util.*;
  3.  
  4. class Product{
  5. private int cost, num;
  6. static int sum = 0;
  7.  
  8. Product(int cost, int num){
  9. this.cost = cost;
  10. this.num = num;
  11. productSum();
  12. }
  13.  
  14. private void productSum() {
  15. sum += cost * num;
  16. }
  17. }
  18. /* Name of the class has to be "Main" only if the class is public. */
  19. class Ideone
  20. {
  21. public static void main (String[] args) throws java.lang.Exception
  22. {
  23. // your code goes here
  24. Scanner sc = new Scanner(System.in);
  25. int x = sc.nextInt();
  26. int n = sc.nextInt();
  27.  
  28. Product[] p = new Product[n];
  29.  
  30. for(int i = 0; i < n; i++)
  31. p[i] = new Product(sc.nextInt(), sc.nextInt());
  32.  
  33. String result = (x == Product.sum) ? "Yes" : "No";
  34. System.out.println(result);
  35. sc.close();
  36. }
  37. }
Success #stdin #stdout 0.13s 49516KB
stdin
260000
4
20000 5
30000 2
10000 6
5000 8
stdout
Yes