QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#678258#9529. Farm Managementucup-team3584#WA 0ms3800kbC++232.5kb2024-10-26 14:28:082024-10-26 14:28:09

Judging History

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

  • [2024-10-26 14:28:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3800kb
  • [2024-10-26 14:28:08]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll m;
    cin >> m;
    vector<ll> w(n), l(n), r(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> l[i] >> r[i];
    }
    vector<int> id(n);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int i, int j) { return w[i] > w[j]; });
    ll sum = 0, rem = m;
    for (int i = 0; i < n; ++i) {
        sum += w[id[i]] * l[id[i]];
        rem -= l[id[i]];
    }
    ll res = 0;
    res = max(res, sum + rem * w[id[0]]);
    vector<pair<ll, ll>> v;
    vector<ll> used = l;
    for (int i = 0; i < n; ++i) {
        if (rem >= r[id[i]] - l[id[i]]) {
            rem -= r[id[i]] - l[id[i]];
            sum += w[id[i]] * (r[id[i]] - l[id[i]]);
            used[id[i]] = r[id[i]];
        } else {
            sum += w[id[i]] * rem;
            v.emplace_back(w[id[i]], r[id[i]] - l[id[i]] - rem);
            used[id[i]] += rem;
            rem = 0;
        }
    }
    if (!v.empty()) {
        vector<ll> s(v.size());
        s[0] = v[0].second;
        v[0].second = v[0].first * v[0].second;
        for (int i = 1; i < v.size(); ++i) {
            s[i] = s[i - 1] + v[i].second;
            v[i].second = v[i].first * v[i].second + v[i - 1].second;
        }
        for (int i = 0; i < n; ++i) {
            int L = -1, R = v.size();
            while (R - L > 1) {
                int mid = (L + R) / 2;
                if (v[i].first < w[i]) {
                    R = mid;
                } else {
                    if (L - 1 >= 0 and s[L - 1] > used[i]) {
                        R = mid;
                    } else {
                        L = mid;
                    }
                }
            }
            ll sub = (L - 1 >= 0 ? s[L - 1] : 0);
            ll add = min(used[i] - sub, s[L] - sub);
            sub += add;
            res = max(res, sum - w[i] * sub + (L - 1 >= 0 ? v[L - 1].second : 0) + add * v[L].first);
        }
    }
    cout << res << endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

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

output:

109

result:

ok single line: '109'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3800kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

36948351

result:

wrong answer 1st lines differ - expected: '35204500', found: '36948351'