QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695056#9529. Farm ManagementpWA 0ms3672kbC++171.3kb2024-10-31 19:14:182024-10-31 19:14:21

Judging History

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

  • [2024-10-31 19:14:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3672kb
  • [2024-10-31 19:14:18]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
const int N = 1e5 + 10;

int pre[N];
int prenum[N];
int sum = 0, num = 0;

struct node
{
    int l, r, w;
}g[N];

bool cmp(node a, node b)
{
    return a.w > b.w;
}

int pd(int z, int i)
{
    int l = 0, r = i;
    int ans = 0;

    while (l <= r)
    {
        int mid = l + r >> 1;
        if (pre[mid] < z) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    int t = z - pre[l];
    return t * g[i].w + prenum[l];
}

void solve()
{
    cin >> n >> m;
    for (int i = 0; i < n; i ++)
    {
        cin >> g[i].w >> g[i].l >> g[i].r;
        sum += g[i].w * g[i].l;
        num += g[i].l;
    }

    int ans = 0;
    sort(g, g + n, cmp);
    for (int i = 0; i < n; i ++) //把i弄到最多
    {
        pre[i] = pre[i - 1] + g[i].r - g[i].l;
        prenum[i] = prenum[i - 1] + (g[i].r - g[i].l) * g[i].w;
    }
    for (int i = 0; i < n; i ++)
    {
        int nowsum = sum - g[i].l * g[i].w;
        int nownum = m - num + g[i].l;
        ans = max(ans, nowsum + pd(nownum, i));
    }
    cout << ans << "\n";
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int T = 1;
    while (T --)
       solve();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3672kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

184

result:

wrong answer 1st lines differ - expected: '109', found: '184'