-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
53 lines (52 loc) · 848 Bytes
/
Copy pathB.cpp
File metadata and controls
53 lines (52 loc) · 848 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
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,nn;
cin>>n>>m;
nn=n;
int a[m],b[m];
for(int i=0;i<m;i++)
{
cin>>a[i];
b[i]=a[i];
}
int min=1001,max=0,c1=0,c2=0,j1,j2;
while(n>0)
{
min=1001;
max=0;
for(int i=0;i<m;i++)
{
if(a[i]>max)
{
max=a[i];
j1=i;
}
}
if(max>0)
{
c1+=max;
a[j1]--;
}
n--;
}
c2=0;
while(nn>0)
{
min=1001;
for(int i=0;i<m;i++)
{
if(b[i]<min && b[i]!=0)
{
min=b[i];
j2=i;
}
}
c2+=min;
b[j2]--;
nn--;
}
cout<<c1<<' '<<c2;
return 0;
}