Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class tsoc15c2p5 {
- public static class beb {
- int B, D, C, idx;
- beb(int speed, int dist, int claw, int index) {
- this.B = speed;
- this.D = dist;
- this.C = claw;
- this.idx = index;
- }
- }
- public static void main(String[] args) throws IOException {
- int S = readInt(); //ex-convict speed (uniform)
- int N = readInt(); //# of bebiliths in pursuit
- beb arr[] = new beb[N];
- for (int i=0; i<N; i++) { //1st, 2nd, 3rd... bebiliths
- arr[i] = new beb(readInt(), readInt(), readInt(), i+1);
- //B = speed, D = venom distance, C = claw sharpness
- }
- Arrays.sort(arr, new Comparator<beb>() {
- public int compare(beb e1, beb e2) {
- if (e1.B!=e2.B) {
- return e2.B-e1.B;
- } else if (e1.B==e2.B && e1.B>=S && e1.C==e2.C) {
- return e2.C-e1.C;
- } else if (e1.B==e2.B && e1.B<S && e1.D!=e2.D) {
- return e2.D-e1.D;
- } else {
- return e1.idx-e2.idx;
- }
- }
- });
- // if (e1.B>=S && e2.B>=S && e1.B==e2.B) { //- same speed but B>S, sharper claws = more dangerous
- // return e2.C - e1.C;
- // } else if (e1.B<S && e2.B<S && e1.B==e2.B) { //- same speed but B<S, farthese venom = more dangerous
- // return e2.D - e1.D;
- // } else if (e1.B!=e2.B) { //- faster = more dangerous
- // return e2.B-e1.B;
- // } else {
- // return e2.idx - e1.idx;
- // }
- // }
- // });
- int Q = readInt();
- for (int i=0; i<Q; i++) {
- int x = readInt(); //x'th most dangerous
- System.out.println(arr[x-1].idx);
- }
- exit();
- }
- final private static int BUFFER_SIZE = 1 << 16;
- private static DataInputStream din = new DataInputStream(System.in);
- private static byte[] buffer = new byte[BUFFER_SIZE];
- private static int bufferPointer = 0, bytesRead = 0;
- static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
- public static String readLine() throws IOException {
- byte[] buf = new byte[64]; // line length
- int cnt = 0, c;
- while ((c = Read()) != -1) {
- if (c == '\n')
- break;
- buf[cnt++] = (byte) c;
- }
- return new String(buf, 0, cnt);
- }
- public static String read() throws IOException{
- byte[] ret = new byte[1024];
- int idx = 0;
- byte c = Read();
- while (c <= ' ') {
- c = Read();
- }
- do {
- ret[idx++] = c;
- c = Read();
- } while (c != -1 && c != ' ' && c != '\n' && c != '\r');
- return new String(ret, 0, idx);
- }
- public static int readInt() throws IOException {
- int ret = 0;
- byte c = Read();
- while (c <= ' ')
- c = Read();
- boolean neg = (c == '-');
- if (neg)
- c = Read();
- do {
- ret = ret * 10 + c - '0';
- } while ((c = Read()) >= '0' && c <= '9');
- if (neg)
- return -ret;
- return ret;
- }
- public static long readLong() throws IOException {
- long ret = 0;
- byte c = Read();
- while (c <= ' ')
- c = Read();
- boolean neg = (c == '-');
- if (neg)
- c = Read();
- do {
- ret = ret * 10 + c - '0';
- } while ((c = Read()) >= '0' && c <= '9');
- if (neg)
- return -ret;
- return ret;
- }
- public static double readDouble() throws IOException {
- double ret = 0, div = 1;
- byte c = Read();
- while (c <= ' ')
- c = Read();
- boolean neg = (c == '-');
- if (neg)
- c = Read();
- do {
- ret = ret * 10 + c - '0';
- } while ((c = Read()) >= '0' && c <= '9');
- if (c == '.') {
- while ((c = Read()) >= '0' && c <= '9') {
- ret += (c - '0') / (div *= 10);
- }
- }
- if (neg)
- return -ret;
- return ret;
- }
- private static void fillBuffer() throws IOException {
- bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
- if (bytesRead == -1)
- buffer[0] = -1;
- }
- private static byte Read() throws IOException {
- if (bufferPointer == bytesRead)
- fillBuffer();
- return buffer[bufferPointer++];
- }
- public void close() throws IOException {
- if (din == null)
- return;
- din.close();
- }
- static void print(Object o) {
- pr.print(o);
- }
- static void println(Object o) {
- pr.println(o);
- }
- static void flush() {
- pr.flush();
- }
- static void println() {
- pr.println();
- }
- static void exit() throws IOException {
- din.close();
- pr.close();
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement