Thứ Ba, 3 tháng 5, 2022

SCHEDULE C++

#include <bits/stdc++.h>
using namespace std;
int n;
struct oto
{
    int a,b;
};
oto xe[100001];
bool cmp(oto x, oto y)
{
    if(x.b*y.a<y.b*x.a) return true;
    if(x.b*y.a>y.b*x.a) return false;
    return false;
}

void nhap()
{
    cin >> n ;
    for(int i = 1;i <= n;i++) cin>>xe[i].a;
    for(int i = 1;i <= n;i++) cin>>xe[i].b;
}
long long s[100005];
void xuly()
{
    sort(xe+1,xe+1+n,cmp);

    s[0]=0;
    for(int i=1;i<=n;i++) s[i]=s[i-1]+xe[i].b;
    long long res=0;
    for(int i = 1;i <= n;++i)
    {
        res=res+xe[i].a*s[i];
    }
    cout<<res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen("schedule.inp","r",stdin);
    freopen("schedule.out","w",stdout);
    nhap();
    xuly();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.