QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#715033 | #9529. Farm Management | ljljljlj# | WA | 0ms | 3612kb | C++20 | 2.0kb | 2024-11-06 10:02:33 | 2024-11-06 10:02:35 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
using i64 = long long;
const int inf = 1e18;
void solve()
{
int n, m;
cin >> n >> m;
vector<tuple<int, int, int>> a(n + 1);
for (int i = 1, w, l, r; i <= n; i++)
{
cin >> w >> l >> r;
a[i] = make_tuple(w, l, r);
}
sort(a.begin() + 1, a.end(), [](auto &x, auto &y)
{ return get<0>(x) != get<0>(y) ? get<0>(x) > get<0>(y) : get<2>(x) > get<2>(y); });
vector<int> pre(n + 1), suf(n + 2);
vector<int> presum(n + 1), sufsum(n + 2);
for (int i = 1; i <= n; i++)
{
pre[i] = pre[i - 1] + get<2>(a[i]);
presum[i] += presum[i - 1] + get<0>(a[i]) * get<2>(a[i]);
}
for (int i = n; i >= 1; i--)
{
suf[i] = suf[i + 1] + get<1>(a[i]);
sufsum[i] = sufsum[i + 1] + get<0>(a[i]) * get<1>(a[i]);
}
int mx = 0;
for (int i = 1; i <= n; i++)
{
if (pre[i - 1] + suf[i + 1] > m)
{
int L = 1, R = i - 1, ans = -1;
auto check = [&](int mid) -> bool
{
int res = pre[mid] + suf[mid + 1] - get<1>(a[i]);
return res <= m;
};
while (L <= R)
{
int mid = L + R >> 1;
if (check(mid))
ans = mid, L = mid + 1;
else
R = mid - 1;
}
int res = 0;
res = sufsum[ans + 1] - get<0>(a[i]) * get<1>(a[i]) + presum[ans] + (m - pre[ans] - suf[ans + 1]) * get<0>(a[ans + 1]);
mx = max(mx, res);
}
else
mx = max(mx, presum[i - 1] + sufsum[i + 1] + (m - pre[i - 1] - suf[i + 1]) * get<0>(a[i]));
}
cout << mx << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
solve();
// system("pause");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 3576kb
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:
32281150
result:
wrong answer 1st lines differ - expected: '35204500', found: '32281150'