-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestClass.java
More file actions
45 lines (35 loc) · 949 Bytes
/
Copy pathTestClass.java
File metadata and controls
45 lines (35 loc) · 949 Bytes
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
import java.util.*;
class TestClass {
public static int max(int a, int b)
{
if(a > b)
{
return a;
}
else
{
return b;
}
}
public static void main(String args[] ){
Scanner s = new Scanner(System.in);
int N = s.nextInt();
int att[] = new int[N];
int pos[] = new int[N];
int sum = 0;
int diff;
for (int i = 0; i < N; i++) {
att[i] = s.nextInt();
pos[i] = s.nextInt();
}
for(int j=0;j<N-1;j++)
{
for(int k=j+1;k<N;k++)
{
diff = Math.abs(pos[k] - pos[j]);
sum = sum + diff * max(att[k], att[j]);
}
}
System.out.print(sum);
}
}