QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691144#9529. Farm ManagementWA_automaton#WA 0ms3584kbC++201.7kb2024-10-31 10:06:212024-10-31 10:06:23

Judging History

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

  • [2024-10-31 10:06:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3584kb
  • [2024-10-31 10:06:21]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
void debug() {std::cerr << "\n";}
template<class T, class... OtherArgs>
void debug(T &&var, OtherArgs &&... args) {
    std::cerr << std::forward<T>(var) << " ";
    debug(std::forward<OtherArgs>(args)...);
}
#define SZ(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using i64 = long long;
using u64 = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
constexpr int N = 300010;
constexpr int P = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<array<int, 3>> a(n);
    int t = 0, cost = 0;
    for (int i = 0; i < n; i++) {
        auto &[w, l, r] = a[i];
        cin >> w >> l >> r;
        m -= l;
        cost += w * l;
    }
    
    sort(all(a));

    vector<int> suf(n + 1), sufres(n + 1);
    for (int i = n - 1; ~i; i--) {
        auto &[w, l, r] = a[i];
        suf[i] = suf[i + 1] + r - l;
        sufres[i] = sufres[i + 1] + (r - l) * w;
    }

    int ans = cost;
    for (int i = 0; i < n; i++) {
        auto &[w, l, r] = a[i];
        int rest = m + l;
        int j = lower_bound(all(suf), rest, greater()) - suf.begin();
        // debug("?", i, j, rest, sufres[j + 1]);
        rest -= suf[j + 1];
        ans = max(ans, cost - w * l + sufres[j + 1] + rest * a[j][0]);
    }
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    int _ = 1;
    // cin >> _;
    while (_--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3552kb

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:

34950156

result:

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