QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682085#9529. Farm Managementwht11WA 1ms7732kbC++142.2kb2024-10-27 13:50:012024-10-27 13:50:01

Judging History

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

  • [2024-10-27 13:50:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7732kb
  • [2024-10-27 13:50:01]
  • 提交

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define frep(i, l, r) for (int i = l; i >= r; i--)
#define eb emplace_back
#define pb push_back
#define endl "\n"
// #define int long long
using namespace std;
using PII = pair<int, int>;
const int N = 1e6 + 3;
const int inf = 0x3f3f3f3f;
int n, m;
struct node
{
    int w, l, r;
} a[N], b[N];
bool cmp1(node a, node b) { return a.w > b.w; }
int sl[N], sr[N], ll[N], rr[N], s[N];
int pos, num, ww;
bool check(int x)
{
    if (s[x] <= ww)
        return true;
    return false;
}
void solve()
{
    cin >> n >> m;
    rep(i, 1, n) cin >> a[i].w >> a[i].l >> a[i].r, b[i] = a[i];
    sort(a + 1, a + 1 + n, cmp1);
    rep(i, 1, n)
    {
        ll[i] = ll[i - 1] + a[i].l;
        rr[i] = rr[i - 1] + a[i].r;
        sl[i] = sl[i - 1] + a[i].w * a[i].l;
        sr[i] = sr[i - 1] + a[i].w * a[i].r;
    }
    int ans = a[1].w * (m - (ll[n] - ll[1])) + sl[n] - sl[1];
    rep(i, 1, n)
    {
        if (m < rr[i] + ll[n] - ll[i])
        {
            pos = i;
            num = m - rr[i - 1] - (ll[n] - ll[i]);
            break;
        }
    }
    // cerr << "pos,num:" << pos << "," << num << endl;
    s[pos] = a[pos].r - num;
    rep(i, pos + 1, n) s[i] = s[i - 1] + a[i].r - a[i].l;
    rep(i, pos + 1, n)
    {
        ww = a[i].l;
        int l = pos, r = i, p = pos;
        while (l <= r)
        {
            int mid = l + r >> 1;
            if (check(mid))
            {
                p = mid;
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }
        // cerr << "i,p:" << i << "," << p << endl;
        if (p == i)
        {
            ans = max(ans, sr[p - 1] + (ww - s[p - 1]) * a[p].w + sl[n] - sl[p]);
        }
        else
        {
            ans = max(ans, sr[p - 1] + (ww - s[p - 1] + a[p].l) * a[p].w + sl[n] - sl[p] - ww * a[i].w);
        }
        // cerr << "ans:" << ans << endl;
    }
    cout << ans << endl;
}

signed main()
{
    IOS;
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
}

詳細信息

Test #1:

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

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

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'