fork download
  1. class Item{
  2. int upTo, quantity;
  3. void set(int upTo, int quantity) {
  4. this.upTo = upTo; this.quantity = quantity;
  5. }
  6. }
  7. class MyComparator implements Comparator<Item>{
  8. public int compare(Item one, Item two){
  9. if(one.upTo != two.upTo)
  10. return one.upTo - two.upTo;
  11. return 0;
  12. }
  13. }
  14.  
  15. public String isFair(int n, int b, int[] upTo, int[] quantity) {
  16. int q = upTo.length;
  17. Item[] t = new Item[q+1];
  18. for(int i = 0; i < q; ++i) {
  19. t[i] = new Item();
  20. t[i].set(upTo[i], quantity[i]);
  21. }
  22. t[q] = new Item();
  23. t[q].set(b, n);
  24. Arrays.sort(t, new MyComparator());
  25. int prev_upTo = 0, prev_quan = 0;
  26. String YES = "fair";
  27. String NO = "unfair";
  28. int min_even = 0, max_even = 0;
  29. for(int i = 0; i < q+1; ++i) {
  30. int even = 0, odd = 0;
  31. for(int j = prev_upTo + 1; j <= t[i].upTo; ++j) {
  32. if(j % 2 == 0) ++even;
  33. else ++odd;
  34. }
  35. int quan = t[i].quantity - prev_quan;
  36. if(quan < 0 || quan > even + odd) return NO;
  37. prev_upTo = t[i].upTo;
  38. prev_quan = t[i].quantity;
  39. min_even += Math.max(0, quan - odd);
  40. max_even += Math.min(even, quan);
  41. }
  42. // System.out.println(min_even + " " + max_even);
  43. if(min_even <= n/2 && n/2 <= max_even) return YES;
  44. return NO;
  45. }
  46.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:1: error: expected ';' after class definition
 }
 ^
prog.cpp: In member function 'void Item::set(int, int)':
prog.cpp:4:14: error: request for member 'upTo' in '(Item*)this', which is of pointer type 'Item*' (maybe you meant to use '->' ?)
         this.upTo = upTo; this.quantity = quantity;
              ^
prog.cpp:4:32: error: request for member 'quantity' in '(Item*)this', which is of pointer type 'Item*' (maybe you meant to use '->' ?)
         this.upTo = upTo; this.quantity = quantity;
                                ^
prog.cpp: At global scope:
prog.cpp:7:31: error: expected initializer before 'Comparator'
 class MyComparator implements Comparator<Item>{
                               ^
stdout
Standard output is empty