-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP178PROJ.cpp
More file actions
39 lines (32 loc) · 756 Bytes
/
Copy pathP178PROJ.cpp
File metadata and controls
39 lines (32 loc) · 756 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
#include<bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Ford(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define here cout<<"I am Here"<<endl;
int const maxn = 1000000;
int const base = 1e9 + 7;
priority_queue < int, vector <int>, greater<int> > Qu;
int main(void){
int N;
int K;
cin>>N;
For(i, 1, N){
cin>>K;
Qu.push(K);
}
long long res = 0;
while(Qu.empty() == false){
int l, r;
l = Qu.top();
Qu.pop();
r = Qu.top();
Qu.pop();
res = ( res + 1ll * (l + r)) % base;
if(Qu.empty() == false){
Qu.push((l+r) % base);
}
}
cout<<res<<endl;
return 0;
}