Skip to content

Instantly share code, notes, and snippets.

@hiroshi-cl
Created June 25, 2013 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroshi-cl/5856726 to your computer and use it in GitHub Desktop.
Save hiroshi-cl/5856726 to your computer and use it in GitHub Desktop.
2010年 模擬地区予選 Problem A : Era Name [Licence: NYSL Version 0.9982]
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main {
public static void main(String... args) {
new Main().run();
}
public void run() {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int N = sc.nextInt();
int Q = sc.nextInt();
if(N == 0 && Q == 0)
return;
S[] ss = new S[N];
for (int i = 0; i < N; i++) {
String s = sc.next();
int p = sc.nextInt();
int q = sc.nextInt();
ss[i] = new S(q - p, q, s);
}
loop: for (int i = 0; i < Q; i++) {
int y = sc.nextInt();
for (int j = 0; j < N; j++)
if (ss[j].s < y && y <= ss[j].t) {
System.out.println(ss[j].name + " " + (y - ss[j].s));
continue loop;
}
System.out.println("Unknown");
}
}
}
class S {
final int s, t;
final String name;
public S(int s, int t, String name) {
this.s = s;
this.t = t;
this.name = name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment