QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#684557#9529. Farm Management_LSA_#WA 1ms5752kbC++141.4kb2024-10-28 14:22:412024-10-28 14:22:44

Judging History

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

  • [2024-10-28 14:22:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5752kb
  • [2024-10-28 14:22:41]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
ll read(){
    ll X = 0 ,r = 1;
    char ch = getchar();
    while(!isdigit(ch) && ch != '-') ch = getchar();
    if(ch == '-') r = -1,ch = getchar();
    while(isdigit(ch)) X = X*10+ch-'0',ch = getchar();
    return X*r;
}
const int N = 1e5+10;
int n; ll m,ans;
struct node{
    ll w,l,r;
}a[N];
ll suf[N],valsuf[N],pre[N],valpre[N];
ll s1[N],s2[N];
void solve(){
    n = read(); m = read();
    for(int i=1;i<=n;i++){
        ll w = read(),l = read(),r = read();
        a[i] = node{w,l,r};
    }
    sort(a+1,a+1+n,[](node x,node y){return x.w == y.w ? x.l < y.l : x.w > y.w;});
    
    for(int i=n;i;i--){
        suf[i] += a[i].l+suf[i+1];
        valsuf[i] += a[i].l*a[i].w+valsuf[i+1];
    }
    for(int i=1;i<=n;i++){
        pre[i] += pre[i-1]+a[i].l;
        valpre[i] += valpre[i-1]+a[i].l*a[i].w;
    }
    
    for(int i=1;i<=n;i++){
        ll rest = m-(pre[i-1]+suf[i+1]);
        int id = upper_bound(s1,s1+i,rest)-s1-1;
        ll now = valpre[i-1]+valsuf[i+1]+s2[id]+(rest-s1[id])*a[i].w;
        ans = max(ans,now);
        s1[i] = s1[i-1]+a[i].r-a[i].l;
        s2[i] = s2[i-1]+(a[i].r-a[i].l)*a[i].w;
    }
    cout << ans;
}
signed main(){
    int T = 1;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5676kb

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'