QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693080#9529. Farm ManagementranxiWA 0ms3556kbC++141.7kb2024-10-31 15:30:092024-10-31 15:30:11

Judging History

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

  • [2024-10-31 15:30:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3556kb
  • [2024-10-31 15:30:09]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define alls(x) x.begin(),x.end()
#define ull unsigned long long
#define lowbit(x) x&-x
#define lc p<<1
#define rc p<<1|1
#define PII pair<int,int>
#define vi vector<int>
#define int long long

using namespace std;
const ll inf = 2e18;
const int mod = 998244353;
const int N = 1e6+10;
struct node{
    int w,l,r;
    bool operator<(node const &o)const{
        return w<o.w;
    }
};
void solve()
{
    int n;
    ll m;
    cin >> n>> m;
    vector<node>a(n+1);
    for(int i = 1;i<=n;i++)
    {
        cin >> a[i].w >> a[i].l>>a[i].r;
    }
    sort(a.begin(),a.end());
    reverse(a.begin()+1,a.end());
    ll base = 0;
    vi s(n+1);
    for(int i = 1;i<=n;i++)
    {
        base += a[i].w * a[i].l;
        s[i] = s[i-1] + a[i].w * a[i].l;
        m-=a[i].l;
    }
    vi pre(n+1),pre_val(n+1);
    for(int i = 1;i<=n;i++)
    {
        pre[i] = pre[i-1] + (a[i].r - a[i].l);
        pre_val[i] = pre_val[i-1] + (a[i].r-a[i].l)*a[i].w;
    }
    int ans = 0;
    for(int i = 1;i<=n;i++)
    {
        //case 1:全给i
        int u = m+a[i].l;
        if(u>=pre[i-1])
        {
            u-=pre[i-1];
            int x = base-a[i].l*a[i].w+pre_val[i-1];
            x+=u*a[i].w;
            ans = max(ans,x);
        }
        else
        {
            int pos = upper_bound(alls(pre),u) - pre.begin()-1;
            u-=pre[pos];
            int x = base + pre_val[pos] + u*a[pos+1].w;
            ans =  max(ans,x);
        }
    }
    cout<<ans<<'\n';
}
signed main()
{
    cout<<fixed<<setprecision(6);
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1;
    // cin >> _;
    while(_--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

40000533

result:

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