-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmaximum subset array.cpp
85 lines (57 loc) · 2.01 KB
/
maximum subset array.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
#include<set>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
long long int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
set<int> s;
long long int max=a[0];
int j=0;
for(int i=1;i<n;i++)
{
if(max<a[i])
{
max=a[i];
j=i;
}
}
a[j]=-1;
s.insert(max);int p;
unsigned long long int sum=0;
if(max>=0)
{
sum=max;
for(int i=0;i<n;i++)
{
if(a[i]>=0)
{
sum=sum+a[i];
s.insert(a[i]);
}
}
p=s.size();
unsigned long long int q=1;
for(int i=0;i<=p-1;i++)
{
q=q*2;
q=q%1000000009;
}
}
if(max>=0)
cout<<sum<<" "<<q<<endl;
else
cout<<max<<" "<<q<<endl;
}
system ("pause");
return 0;
}