Submission #329658

#TimeUsernameProblemLanguageResultExecution timeMemory
329658anishrajeevUntitled (POI11_tem)Java
0 / 100
849 ms65536 KiB
import java.io.*; import java.util.*; public class tem { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader bf = new BufferedReader(new FileReader("tester.in")); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int N = Integer.parseInt(bf.readLine()); pair[] x = new pair[N]; pair[] temps = new pair[N]; for(int i = 0; i < N; i++){ StringTokenizer stk = new StringTokenizer(bf.readLine()); int a = Integer.parseInt(stk.nextToken()); int b = Integer.parseInt(stk.nextToken()); temps[i] = new pair(a, b); } x[N-1] = new pair(1, temps[N-1].y); for(int i = N-2; i >= 0; i--){ int match = match(temps[i], temps[i+1], x[i+1]); if(match != -1)x[i] = new pair(x[i+1].x+1, match); else x[i] = new pair(1, temps[i].y); } int answer = 0; for(int i = 0; i < N; i++) answer = Math.max(answer, x[i].x); System.out.println(answer); } public static int match(pair p1, pair p2, pair x){ //p1 = temp[i] //p2 = temp[i+1] //x = x[i+1] if(p1.x <= x.y && x.y <= p1.y) return x.y; if(p1.y <= x.y)return p1.y; return -1; } public static class pair{ int x, y; public pair(int a, int b){ x = a; y = b; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...