Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class tsoc15c2p5 {
  4.  
  5. public static class beb {
  6. int B, D, C, idx;
  7. beb(int speed, int dist, int claw, int index) {
  8. this.B = speed;
  9. this.D = dist;
  10. this.C = claw;
  11. this.idx = index;
  12. }
  13. }
  14.  
  15.  
  16. public static void main(String[] args) throws IOException {
  17.  
  18. int S = readInt(); //ex-convict speed (uniform)
  19. int N = readInt(); //# of bebiliths in pursuit
  20. beb arr[] = new beb[N];
  21. for (int i=0; i<N; i++) { //1st, 2nd, 3rd... bebiliths
  22. arr[i] = new beb(readInt(), readInt(), readInt(), i+1);
  23. //B = speed, D = venom distance, C = claw sharpness
  24. }
  25.  
  26. Arrays.sort(arr, new Comparator<beb>() {
  27. public int compare(beb e1, beb e2) {
  28. if (e1.B!=e2.B) {
  29. return e2.B-e1.B;
  30. } else if (e1.B==e2.B && e1.B>=S && e1.C==e2.C) {
  31. return e2.C-e1.C;
  32. } else if (e1.B==e2.B && e1.B<S && e1.D!=e2.D) {
  33. return e2.D-e1.D;
  34. } else {
  35. return e1.idx-e2.idx;
  36. }
  37. }
  38. });
  39.  
  40. // if (e1.B>=S && e2.B>=S && e1.B==e2.B) { //- same speed but B>S, sharper claws = more dangerous
  41. // return e2.C - e1.C;
  42. // } else if (e1.B<S && e2.B<S && e1.B==e2.B) { //- same speed but B<S, farthese venom = more dangerous
  43. // return e2.D - e1.D;
  44. // } else if (e1.B!=e2.B) { //- faster = more dangerous
  45. // return e2.B-e1.B;
  46. // } else {
  47. // return e2.idx - e1.idx;
  48. // }
  49. // }
  50. // });
  51.  
  52. int Q = readInt();
  53. for (int i=0; i<Q; i++) {
  54. int x = readInt(); //x'th most dangerous
  55. System.out.println(arr[x-1].idx);
  56. }
  57.  
  58. exit();
  59. }
  60.  
  61. final private static int BUFFER_SIZE = 1 << 16;
  62. private static DataInputStream din = new DataInputStream(System.in);
  63. private static byte[] buffer = new byte[BUFFER_SIZE];
  64. private static int bufferPointer = 0, bytesRead = 0;
  65. static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  66.  
  67. public static String readLine() throws IOException {
  68. byte[] buf = new byte[64]; // line length
  69. int cnt = 0, c;
  70. while ((c = Read()) != -1) {
  71. if (c == '\n')
  72. break;
  73. buf[cnt++] = (byte) c;
  74. }
  75. return new String(buf, 0, cnt);
  76. }
  77. public static String read() throws IOException{
  78. byte[] ret = new byte[1024];
  79. int idx = 0;
  80. byte c = Read();
  81. while (c <= ' ') {
  82. c = Read();
  83. }
  84. do {
  85. ret[idx++] = c;
  86. c = Read();
  87. } while (c != -1 && c != ' ' && c != '\n' && c != '\r');
  88. return new String(ret, 0, idx);
  89. }
  90. public static int readInt() throws IOException {
  91. int ret = 0;
  92. byte c = Read();
  93. while (c <= ' ')
  94. c = Read();
  95. boolean neg = (c == '-');
  96. if (neg)
  97. c = Read();
  98. do {
  99. ret = ret * 10 + c - '0';
  100. } while ((c = Read()) >= '0' && c <= '9');
  101.  
  102. if (neg)
  103. return -ret;
  104. return ret;
  105. }
  106.  
  107. public static long readLong() throws IOException {
  108. long ret = 0;
  109. byte c = Read();
  110. while (c <= ' ')
  111. c = Read();
  112. boolean neg = (c == '-');
  113. if (neg)
  114. c = Read();
  115. do {
  116. ret = ret * 10 + c - '0';
  117. } while ((c = Read()) >= '0' && c <= '9');
  118. if (neg)
  119. return -ret;
  120. return ret;
  121. }
  122.  
  123. public static double readDouble() throws IOException {
  124. double ret = 0, div = 1;
  125. byte c = Read();
  126. while (c <= ' ')
  127. c = Read();
  128. boolean neg = (c == '-');
  129. if (neg)
  130. c = Read();
  131.  
  132. do {
  133. ret = ret * 10 + c - '0';
  134. } while ((c = Read()) >= '0' && c <= '9');
  135.  
  136. if (c == '.') {
  137. while ((c = Read()) >= '0' && c <= '9') {
  138. ret += (c - '0') / (div *= 10);
  139. }
  140. }
  141.  
  142. if (neg)
  143. return -ret;
  144. return ret;
  145. }
  146.  
  147. private static void fillBuffer() throws IOException {
  148. bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  149. if (bytesRead == -1)
  150. buffer[0] = -1;
  151. }
  152.  
  153. private static byte Read() throws IOException {
  154. if (bufferPointer == bytesRead)
  155. fillBuffer();
  156. return buffer[bufferPointer++];
  157. }
  158.  
  159. public void close() throws IOException {
  160. if (din == null)
  161. return;
  162. din.close();
  163. }
  164.  
  165. static void print(Object o) {
  166. pr.print(o);
  167. }
  168.  
  169. static void println(Object o) {
  170. pr.println(o);
  171. }
  172.  
  173. static void flush() {
  174. pr.flush();
  175. }
  176.  
  177. static void println() {
  178. pr.println();
  179. }
  180.  
  181. static void exit() throws IOException {
  182. din.close();
  183. pr.close();
  184. System.exit(0);
  185. }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement