0
点赞
收藏
分享

微信扫一扫

E. Two Arrays and Sum of Functions(数学问题) Codeforces Round #560 (Div. 3)

原题链接: ​​https://codeforces.com/contest/1165/problem/E​​​E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_#define
样例:

输入
5
1 8 7 2 4
9 7 2 9 3
输出
646
输入
1
1000000
1000000
输出
757402647
输入
2
1 3
4 2
输出
20

题意: 由于改编题的题意写得非常明显,故这里不写题意,这题关键在于解题思路。

解题思路: 为了让这个结果最小,我们就会想到要让最小的E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_acm禁赛_02和最大的E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数组_03配对,可E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_acm禁赛_02的位置是不能变的,我们只能变E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数组_03不能变E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数学_06是因为它所在的位置具有属性,如果我们把这个属性合并到E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数学_06中,那此题就非常好办了。OK,我们开始推导。
由于E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_acm禁赛_08,而我们求得是E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数组_09,这个我们进行展开得到的就是E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数组_10,这个就是一个数学求和公式,此刻我们想要做的就是化简,利用微积分的知识我们可以求得为E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_训练赛_11,此时我们发现E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_训练赛_12也是每个E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数组_13对应的位置,所以我们就是要让E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_数学_14最小,那么我们令E. Two Arrays and Sum of Functions(数学问题)  Codeforces Round #560 (Div. 3)_acm禁赛_15,所以我们只要求得c数组对应的值,再对它由小到大排序,再对b数组由大到小排序即可,这样对应相乘的值自然就是最小的。具体看代码实现。

AC代码:

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (ll i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (ll i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 2e5+2;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

const ll mod =998244353;
ll a[maxn],b[maxn],c[maxn];//c数组为a数组乘上对应出现次数。
bool cmp(ll x,ll y){
return x>y;
}
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
int n;
while(cin>>n){
rep(i,0,n-1)cin>>a[i];
rep(i,0,n-1)cin>>b[i];
rep(i,0,n-1)c[i]=(n-i)*(i+1)*a[i];
sort(c,c+n);
sort(b,b+n,cmp);
ll ans=0;
rep(i,0,n-1){
ans+=c[i]%mod*b[i];
ans%=mod;
}
cout<<ans<<endl;
}
return 0;
}


举报

相关推荐

0 条评论