QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674454#9529. Farm Managementytck#WA 1ms5736kbC++172.0kb2024-10-25 15:52:532024-10-25 15:52:54

Judging History

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

  • [2024-10-25 15:52:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5736kb
  • [2024-10-25 15:52:53]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
#define endl '\n'
#define PII pair<int, int>
#define int long long
//#define int __int128
using namespace std;
inline int read();
inline void write(int x);
const int N = 1e5 + 10, M = 2e3 + 10, mod = 998244353, inf = 1e18, base = 131;
const double eps = 1e-7;
int n, m;
struct node{
    int x, l, r;
}p[N];
int s[N], f[N];
bool cmp(node a, node b){
    return a.x > b.x;
}
void solve(){
    cin >> n >> m;
    int ans = 0;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int a, b, c;
        cin >> a >> b >> c;
        p[i] = {a, b, c};
        ans += b * a;
        cnt += b;
    }
    sort(p + 1, p + 1 + n, cmp);
    for(int i = 1; i <= n; i++){
        s[i] = s[i - 1] + p[i].r - p[i].l;
        f[i] = f[i - 1] + (p[i].r - p[i].l) * p[i].x;
    }
    int res = 0;
    for(int i = 1; i <= n; i++){
        int t = m - cnt + p[i].l;
        if(t >= s[i - 1]){
            t -= s[i - 1];
            res = max(res, ans - p[i].l * p[i].x + f[i - 1] + t * p[i].x);
        }
        else{
            int l = 0, r = i - 1;
            while(l < r){
                int mid = l + r + 1 >> 1;
                if(t >= s[mid]){
                    l = mid;
                }
                else r = mid - 1;
            }
            t -= s[l];
            res = max(res, ans - p[i].l * p[i].x + f[l] + t * p[i].x);
        }
    }
    cout << res << endl;
}
signed main() {
    IOS;
    int T = 1;
    //cin >> T;
    while (T--){
        solve();
    }
}
inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
    return x * f;
}
inline void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5736kb

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

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:

34859047

result:

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