-
Notifications
You must be signed in to change notification settings - Fork 360
/
Hamiltonian and Lagrangian
46 lines (36 loc) · 1.22 KB
/
Hamiltonian and Lagrangian
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.*;
import java.lang.*;
import java.io.*;
// HackerEarth
public class TestClass
{
public static void main (String[] ar)
{
try
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int n = Integer.parseInt(br.readLine());
int a[] = new int[n];
String x[] = br.readLine().trim().split(" ");
for(int i=0;i<x.length;++i)
a[i] = Integer.parseInt(x[i]);
for(int i=0;i<n;++i)
{
int count = 0;
for(int j=i+1;j<n;++j)
{
if(a[i]>a[j])
count++;
}
if(count == (n-1-i))
System.out.print(a[i] + " ");
}
br.close();
isr.close();
}
catch(Exception e)
{
}
}
}