-
Notifications
You must be signed in to change notification settings - Fork 51
/
Question22.java
47 lines (46 loc) · 1005 Bytes
/
Question22.java
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
47
import java.util.*;
class Solution{
public static double solve(int[] arr,int n,int m)
{
if(n==m){
double sum=0;
for(int i =0;i<n;i++)
sum+=arr[i];
return sum;
}
else{
double sum=0f;
double max=Integer.MIN_VALUE;
for(int i=0;i<n;i++)
sum+=arr[i];
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
double tem = sum-(arr[i]+arr[j]);
double temp=(arr[i]+arr[j])/2.0;
if((tem+temp)>max)
{
max=tem+temp;
}
}
}
return max;
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int testcase = sc.nextInt();
for(int x=1;x<=testcase;x++)
{
int n=sc.nextInt();
int m=sc.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
double sol = solve(arr,n,m);
System.out.println("Case #"+x+":"+sol);
}
}
}