-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
30 lines (29 loc) · 685 Bytes
/
E.cpp
File metadata and controls
30 lines (29 loc) · 685 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
#include "bits/stdc++.h"
using namespace std;
#define ll long long
int main() {
ll n;
cin>>n;
vector<pair<ll,ll>>a(n);
vector<ll>b(n);
for(auto &ele : a )cin>>ele.first;
for(int i = 0 ; i <n;i++){
a[i].second=i+1;
}
for(int i = 0 ; i<n;i++){
a[i].first*=(a[i].second*(n-a[i].second+1));
}
for(auto &ele : b)cin>>ele;
sort(a.begin(),a.end());
sort(b.begin(),b.end(),greater<int>());
ll ans = 0;
const int mod = 998244353;
for(int i =0 ; i <n;i++)
{
a[i].first%=mod;
b[i]%=mod;
ans+=(a[i].first*b[i]%mod);
ans%=mod;
}
cout<<ans<<endl;
}