Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4.  
  5. public class _2015
  6. {
  7. static int moneyZhenya;
  8. static int advZhenya1;
  9. static int advZhenya2;
  10.  
  11. public static void main(String[] args)
  12. {
  13. Scanner scanner = new Scanner(System.in);
  14. String s = scanner.nextLine();
  15.  
  16. moneyZhenya = Integer.parseInt(s.split(" ")[0]);
  17. advZhenya1 = Integer.parseInt(s.split(" ")[1]);
  18. advZhenya2 = Integer.parseInt(s.split(" ")[2]);
  19.  
  20. int n = scanner.nextInt(); //количество друзей
  21.  
  22. int[] moneyTogether = new int[n];
  23. int[] advTogether = new int[n];
  24.  
  25. int advFriend;
  26. int moneyFriend;
  27.  
  28. for(int i = 0; i < n; i++)
  29. {
  30. String str = scanner.nextLine();
  31. moneyFriend = Integer.parseInt(str.split(" ")[0]);
  32. advFriend = Integer.parseInt(str.split(" ")[1]);
  33. moneyTogether[i] = moneyZhenya + moneyFriend;
  34. advTogether[i] = advZhenya2 + advFriend;
  35. }
  36.  
  37. int m = scanner.nextInt(); //количество квартир
  38.  
  39. int indexBestApart = 0;
  40. int indexBestFriend = 0;
  41. int advBestApart = -1;
  42. int advApart;
  43. int moneyApart;
  44. boolean bestAlone = false;
  45.  
  46. for(int j = 0; j < m; j++)
  47. {
  48. s = scanner.nextLine();
  49. moneyApart = Integer.parseInt(s.split(" ")[1]);
  50. advApart = Integer.parseInt(s.split(" ")[2]);
  51.  
  52. if(Integer.parseInt(s.split(" ")[0]) == 1) // 1к.кв.
  53. {
  54. advApart = advZhenya1 + advApart;
  55. if(moneyApart <= moneyZhenya && advApart >= advBestApart) //если у Жени есть деньги, и эта квартира лучшая
  56. {
  57. indexBestApart = j;
  58. advBestApart = advApart;
  59. bestAlone = true;
  60. }
  61. }
  62. else
  63. {
  64. for(int i = 0; i < n; i++)
  65. {
  66. advApart = advTogether[i] + advApart;
  67. if(moneyApart <= moneyTogether[i] && advApart >= advBestApart)
  68. {
  69. indexBestApart = j;
  70. indexBestFriend = i;
  71. advBestApart = advApart;
  72. bestAlone = false;
  73. }
  74. }
  75. }
  76.  
  77. if(advBestApart == -1)
  78. {
  79. System.out.println("Forget about apartments. Live in the dormitory.");
  80. }
  81. else if(bestAlone)
  82. {
  83. System.out.println("You should rent the apartment #" + indexBestApart + " alone.");
  84. }
  85. else System.out.println("You should rent the apartment #" + indexBestApart +
  86. " with the friend #" + indexBestFriend + ".");
  87.  
  88. }
  89.  
  90.  
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement