QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695197#9529. Farm ManagementtaijinvjinWA 0ms3772kbC++171.9kb2024-10-31 19:30:512024-10-31 19:30:52

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 19:30:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3772kb
  • [2024-10-31 19:30:51]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

struct node {
    int w, l, r;
};

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::vector<node> a(n + 1);
    int Ans = 0;
    int ans = 0;
    int time = 0;
    for (int i = 1; i <= n; i ++) {
        std::cin >> a[i].w >> a[i].l >> a[i].r;
        ans += a[i].w * a[i].l;
        time += a[i].l;
    }    
    std::cout << ans << "\n";
    sort(a.begin() + 1, a.end(), [&](node a, node b){return a.w < b.w;});
    std::vector<int> b(n + 2), res(n + 2);
    for (int i = n; i >= 1; i --) {
        b[i] = a[i].r - a[i].l;
        res[i] = a[i].w * b[i];
        b[i] += b[i + 1];
        res[i] += res[i + 1];
        // std::cout << b[i] << " " << res[i] << "\n";
    }
    auto Find = [&](int x, int l) -> int {
        int r = n + 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (b[mid] <= x) {
                r = mid;
            }else l = mid + 1;
        }
        return l;
    };
    for (int i = 1; i <= n; i ++) {
    	
        int Res = ans;
        int Time = time;
        if (i == n) {
            Res += a[i].w * (m - Time);
            Ans = std::max(Ans, Res);
            continue;
        }
        Time -= a[i].l;
        Res -= a[i].w * a[i].l;
        if (b[i + 1] <= m - Time) {
            Res += res[i + 1];
            Time += b[i + 1];
            Res += a[i].w * (m - Time);
            Ans = std::max(Ans, Res);
            continue;
        }
        int x = Find(m - Time, i + 1);
        Res += res[x];
        Time += b[x];
        Res += a[x - 1].w * (m - Time);
        
        // std::cout << i << ' ' << x << " " <<  Res << "\n";
        Ans = std::max(Ans, Res);
    }
    std::cout << Ans << "\n";
    

}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    // std::cin >> T;
    while (T --) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3772kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

75
109

result:

wrong answer 1st lines differ - expected: '109', found: '75'