-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC1014.java
More file actions
44 lines (35 loc) · 1.08 KB
/
LC1014.java
File metadata and controls
44 lines (35 loc) · 1.08 KB
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
/*
* LC1014
*/
import java.util.Scanner;
public class LC1014 {
public static int maxScoreSightseeingPair(int[] values) {
int res = 0;
int n = values.length;
// formula v[i] + i
int leftMax = values[0] + 0;
for (int i = 1; i < n; i++) {
// formula v[i] - i
int rightVal = values[i] - i;
res = Math.max(res, leftMax + rightVal);
leftMax = Math.max(leftMax, values[i] + i);
}
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter The Values Array Size : ");
int n = sc.nextInt();
System.out.println();
int[] values = new int[n];
System.out.println("Enter The Values Array Elements : ");
for (int i = 0; i < values.length; i++) {
System.out.printf("%d : ", i);
values[i] = sc.nextInt();
}
System.out.println();
int ans = maxScoreSightseeingPair(values);
System.out.println(ans);
sc.close();
}
}