QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684539 | #9529. Farm Management | Hojstyer# | WA | 0ms | 3812kb | C++20 | 1.4kb | 2024-10-28 14:14:35 | 2024-10-28 14:14:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
ll n, m;
cin >> n >> m;
vector<array<int, 3>> crop(n + 1);
ll res = 0, t = m;
for (int i = 1; i <= n; ++i)
{
int w, l, r;
cin >> w >> l >> r;
crop[i] = {w, l, r};
res += l * w;
t -= l;
}
sort(crop.begin() + 1, crop.begin() + 1 + n, greater<array<int, 3>>());
vector<ll> pre(n + 1), pval(n + 1);
for (int i = 1; i <= n; ++i)
{
auto [w, l, r] = crop[i];
pre[i] = pre[i - 1] + r - l;
pval[i] = pval[i - 1] + 1ll * (r - l) * w;
}
ll ans = res;
for (int i = 1; i <= n; ++i)
{
auto [w, l, r] = crop[i];
ans = max(ans, res + 1ll * t * w);
ll nt = t + l;
int j = lower_bound(pre.begin() + 1, pre.begin() + 1 + n, nt + 1) - pre.begin();
--j;
if (j < i)
ans = max(ans, res - 1ll * l * w + pval[j]);
else
{
int j = lower_bound(pre.begin() + 1, pre.begin() + 1 + n, nt + 1 + r - l) - pre.begin();
--j;
ans = max(ans, res - 1ll * r * w + pval[j]);
}
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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:
34859047
result:
wrong answer 1st lines differ - expected: '35204500', found: '34859047'