-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCover_Them_All!.cpp
More file actions
39 lines (37 loc) · 826 Bytes
/
Cover_Them_All!.cpp
File metadata and controls
39 lines (37 loc) · 826 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<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll M=1000000007;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t,n,sum=0;
cin>>t;
pair<ll,ll> S[200000];
while (t--)
{
sum = 0;
cin>>n;
for (ll i = 0; i < n; i++)
{
cin>>S[i].first;
}
for (ll i = 0; i < n; i++)
{
cin >> S[i].second;
}
sort(S,S+n,[](auto a, auto b){ return a.first < b.first;});
for (ll i = 0; i < n-1; i++)
{
for (ll j = i+1; j < n; j++)
{
sum = (sum + (((S[j].first - S[i].first)%M)*max(S[i].second,S[j].second)%M)%M)%M;
}
}
cout<<sum<<endl;
}
return 0;
}