-
Notifications
You must be signed in to change notification settings - Fork 0
/
218B.cpp
72 lines (71 loc) · 1.48 KB
/
218B.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
#include <bits/stdc++.h>
#define mod 1000000007
#define FOR(i, a, b) for (i = a; i < b; i++)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef priority_queue<ll, vector<ll>, greater<ll>> minheap;
typedef priority_queue<ll> maxheap;
int dxrow[] = {-1, 0, 0, 1, 1, 1, -1, -1}; //first 4 straight last 4 diagonals
int dycol[] = {0, -1, 1, 0, 1, -1, -1, 1};
void printV(vector<ll> v)
{
for (ll i = 0; i < v.size(); i++)
cout << v[i] << "\n";
}
ll power(ll a, ll b)
{
return (ll)(pow(a, b) + 0.5);
}
int modexp(ll A, ll B, ll C)
{
if (A == 0)
return 0;
if (B == 0)
return 1;
ll y;
if (B % 2 == 0)
{
y = modexp(A, B / 2, C);
y = (y * y) % C;
}
else
{
y = A % C;
y = (y * modexp(A, B - 1, C) % C) % C;
}
return (ll)((y + C) % C);
}
int main()
{
ll n, m, x, i;
cin >> n >> m;
ll a[m];
minheap minx;
maxheap maxx;
FOR(i, 0, m)
{
cin >> x;
minx.push(x);
maxx.push(x);
}
ll mina = 0, maxa = 0;
FOR(i, 1, n + 1)
{
ll k = minx.top();
ll k2 = maxx.top();
mina += k;
maxa += k2;
minx.pop();
maxx.pop();
if (k != 1)
minx.push(k - 1);
if (k2 != 1)
maxx.push(k2 - 1);
}
cout << maxa << " " << mina;
}