QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748722#9529. Farm ManagementalheWA 0ms3812kbC++232.0kb2024-11-14 21:12:172024-11-14 21:12:18

Judging History

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

  • [2024-11-14 21:12:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-11-14 21:12:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define re register
#define lowbit(x) (x & (-x))
typedef pair<int, int> PII;
const int INF = 1e18;
const int N = 1e5 + 10;
struct node
{
    int w, l, r, now;
};
node a[N];
void solve()
{
    int n, m;
    cin >> n >> m;
    int sum = 0, ma = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].w >> a[i].l >> a[i].r;
        ma = max(ma, a[i].l);
        sum += a[i].l;
    }
    sort(a + 1, a + n + 1, [&](node x, node y)
         { return x.w < y.w; });
    int u = 0, now = 0;
    for (int i = n; i > 0; i--)
    {
        sum += a[i].r;
        sum -= a[i].l;
        if (sum > m)
        {
            u = i;
            now = m - now + a[i].l;
            break;
        }
        now = sum;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i < u)
            ans += a[i].w * a[i].l, a[i].now = a[i].l;
        else if (i == u)
            ans += now * a[i].w, a[i].now = now;
        else
            ans += a[i].w * a[i].r, a[i].now = a[i].r;
    }
    int p = ans, ans2 = ans;
    vector<int> v(ma + 1);
    int tot = 0;
    for (int i = u; i > 0; i--)
    {
        int l = a[i].now, r = a[i].r;
        while (l < r)
        {
            v[++tot] = v[tot] + a[i].w;
            l++;
            if (tot > ma)
                break;
        }
        if (tot > ma)
            break;
    }
    for (int i = 1; i < u; i++)
    {
        p = ans2;
        p -= a[i].now * a[i].w;
        p += v[a[i].now];
        ans = max(ans, p);
    }
    int ans1 = 0, sum1 = 0;
    for (int i = 1; i < n; i++)
    {
        ans1 += a[i].l * a[i].w;
        sum1 += a[i].l;
    }
    ans1 += (m - sum) * a[n].w;
    ans = max(ans, ans1);
    cout << ans << '\n';
}
int T = 1;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

89367803

result:

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