Created
August 16, 2019 06:17
-
-
Save sreeprasad/b48ae5bd3d815064c62c894a1dd3dd47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void takeExam(int N) throws Exception { | |
TestData[] array = new TestData[N]; | |
for(int i=0;i<N;i++) { | |
array[i] = new TestData(input.nextInt(), input.nextInt()); | |
} | |
Arrays.sort(array, (x,y) -> { | |
return (x.actual!=y.actual) ? (x.actual-y.actual) : (x.allowed-y.allowed); | |
}); | |
int best = -1; | |
for(int i=0;i<N;i++) { | |
if (best <=array[i].allowed) { | |
best = array[i].allowed; | |
} else { | |
best = array[i].actual; | |
} | |
} | |
System.out.printf("%d\n", best); | |
} | |
class TestData { | |
int actual, allowed; | |
public TestData(int actual, int allowed) { | |
this.actual = actual; | |
this.allowed = allowed; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment