QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692577#9529. Farm Managementkonbi#WA 0ms3808kbC++202.4kb2024-10-31 14:43:542024-10-31 14:44:05

Judging History

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

  • [2024-10-31 14:44:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-10-31 14:43:54]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first 
#define se second
using namespace std;
#define pb push_back
#define ls (u << 1)
#define rs (u << 1 | 1)

typedef long long LL;
typedef pair<int, int> PII;

// #define debug(args...) {}
#define debug(args...) { \
     string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
     stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << ' ';
    err(++it, args...);
}

void solve() {
    LL n, m;
    cin >> n >> m;
    vector<array<LL, 3>> a(n + 5);
    for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
    sort(a.begin() + 1, a.begin() + n + 1, [&](auto x, auto y)->int{
        return x[0] < y[0];
    });
    
    LL res = 0, now = 0, nd = m;
    for (int i = 1; i <= n; i++) {
        now += a[i][0] * a[i][1];
        nd -= a[i][1];
    }
    res = now + nd * a[n][0]; // case 1

    vector<LL> sum(n + 5), val(n + 5);
    for (int i = 1; i <= n; i++) {
        auto [w, l, r] = a[i];
        sum[i] = sum[i - 1] + r - l;
        val[i] = val[i - 1] + (r - l) * w;
    }

    auto cal = [&](int ban)->LL {
        int l = 1, r = n;
        while (l < r) {
            int mid = l + r >> 1;
            LL sub = ban >= mid ? (a[ban][2] - a[ban][1]) : 0;
            if (sum[n] - sum[mid - 1] - sub <= nd) r = mid;
            else l = mid + 1;
        }
        int mid = l;
        LL sub = ban >= mid ? (a[ban][2] - a[ban][1]) : 0;
        LL rd = nd - (sum[n] - sum[mid - 1] - sub);
        LL ret = val[n] - val[mid - 1] - sub * a[ban][0];
        if (ban >= mid) ret += rd * a[ban][0];
        else ret += rd * a[mid - 1][0];
        // cerr << ban << ' ' << mid << ' ' << rd << ' ' << ret << ' ' << now << "\n";
        // debug(sum[1], sum[2], sum[3], sum[4]);
        return ret + now;
    };

    res = max(res, cal(0));

    for (int i = 1; i <= n; i++) {
        nd += a[i][1]; now -= a[i][0] * a[i][1];
        res = max(res, cal(i));
        nd -= a[i][1]; now += a[i][0] * a[i][1];
    }

    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tt = 1; //cin >> tt;
    while (tt--) solve();
    return 0;
}
/*
g++ std.cpp -Wall --extra -o std && ./std < in.txt > out.txt
*/

詳細信息

Test #1:

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

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

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:

35309054

result:

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