d046. 例題 P-4-5. 嵩山磨劍坊的問題 (加權最小完成時間) - TCFSH CIRC Judge

本文最後更新於:2024年1月12日 下午

d046. 例題 P-4-5. 嵩山磨劍坊的問題 (加權最小完成時間) - TCFSH CIRC Judge

AP325-d046.cpp

// Author : ysh
// 07/21/2022 Thu 19:55:59.74
// https://judge.tcirc.tw/ShowProblem?problemid=d046
#include<bits/stdc++.h>
using namespace std;
struct box{
    int x,y;
    bool operator<(box a) {
        return x * a.y < a.x * y;
    }
    explicit box(int x = 0,int y = 0):
        x(x), y(y) {};
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    vector<box>f(n);
    for(box &i : f) {
        cin>>i.x;
    }
    for(box &i : f) {
        cin>>i.y;
    }
    sort(f.begin(),f.end());
    long long ans = 0;
    long long last = 0;
    for(box i : f) {
        ans += (last += i.x) * i.y;
    }
    cout<<ans;
    return 0;
}

d046. 例題 P-4-5. 嵩山磨劍坊的問題 (加權最小完成時間) - TCFSH CIRC Judge
http://mysh212.github.io/algosolution/AP325-d046.cpp/
作者
ysh
發布於
2022年7月21日
更新於
2024年1月12日
許可協議