Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. package OlympVsesib15;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.PrintWriter;
  6. import java.util.*;
  7.  
  8. public class Task {
  9. public static void main(String[] args) throws Exception {
  10. ArrayList<Pair> garniturs = new ArrayList<Pair>();
  11. int n, money;
  12.  
  13. Scanner ism = new Scanner(new File("input.txt"));
  14. n = ism.nextInt();
  15. money = ism.nextInt();
  16. for (int i = 0; i<n; i++) {
  17. int type, cost;
  18.  
  19. Pair buffer = new Pair(ism.nextInt(),ism.nextInt());
  20.  
  21. boolean isInside = false;
  22. for (int k = 0; k<garniturs.size(); k++) {
  23. if (garniturs.get(k).index == buffer.index) {
  24. garniturs.get(k).cost = Math.min(garniturs.get(k).cost, buffer.index);
  25. isInside = true;
  26. }
  27. }
  28. if(!isInside) {
  29. garniturs.add(buffer);
  30. }
  31.  
  32. }
  33. garniturs.sort(null);
  34. int ans = 0;
  35. for (int i = 0; i<garniturs.size(); i++) {
  36. if (money - garniturs.get(i).cost>=0) {
  37. money -= garniturs.get(i).cost;
  38. ans++;
  39. } else {
  40. break;
  41. }
  42. }
  43. PrintWriter fw = new PrintWriter(new File("output.txt"));
  44. fw.print(ans);
  45. fw.close();
  46. }
  47. }
  48.  
  49. class Pair implements Comparable<Pair> {
  50. public int index;
  51. public int cost;
  52.  
  53. public Pair(int index, int cost) {
  54. this.index = index;
  55. this.cost = cost;
  56. }
  57.  
  58. @Override
  59. public int compareTo(Pair o) {
  60. return this.cost - o.cost;
  61. }
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement