QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685573 | #9529. Farm Management | megumi# | WA | 0ms | 7724kb | C++17 | 2.4kb | 2024-10-28 20:13:48 | 2024-10-28 20:13:49 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e9, mod = 1e9 + 7;
typedef long long ll;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
f = (c == '-') ? -1 : 1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
struct node {
int x, y, z;
} a[100010];
bool cmp(const node &a, const node &b) {
if (a.x == b.x)
return a.y > b.y;
return a.x < b.x;
}
int b[100010];
int sum[100010]; // 后缀剩余个数
int sum1[100010]; // 后缀剩余钱
int sum2[100010]; // 前缀剩余个数
int sum3[100010]; // 前缀剩余钱
signed main() {
int n = read(), m = read();
for (int i = 1; i <= n; i++)
a[i] = {read(), read(), read()};
sort(a + 1, a + 1 + n, cmp);
int ans = 0, maxx = 0;
int M = m;
for (int i = 1; i <= n; i++) {
M -= a[i].y;
b[i] = a[i].y;
ans += a[i].y * a[i].x;
}
for (int i = n; i >= 1; i--) {
if (M > a[i].z - a[i].y) {
M -= a[i].z - a[i].y;
b[i] = a[i].z;
ans += (a[i].z - a[i].y) * a[i].x;
} else {
ans += M * a[i].x;
b[i] += M;
M = 0;
}
sum[i] = sum[i + 1] + a[i].z - b[i];
sum1[i] = sum1[i + 1] + (a[i].z - b[i]) * a[i].x;
}
for (int i = 1; i <= n; i++) {
sum2[i] = sum2[i - 1] + b[i] - a[i].y;
sum3[i] = sum3[i - 1] + (b[i] - a[i].y) * a[i].x;
// cerr << b[i] << " ";
}
for (int i = 1; i <= n; i++) {
if (b[i] == a[i].y) {
if (b[i] >= sum[i + 1]) {
maxx = max(maxx, ans - sum[i + 1] * a[i].x + sum1[i + 1]);
continue;
}
int l = i + 1, r = n, Ans = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (sum[mid] <= b[i])
r = mid - 1, Ans = mid;
else
l = mid + 1;
}
maxx = max(maxx, ans - b[i] * a[i].x + sum1[Ans] +
(b[i] - sum[Ans]) * a[Ans - 1].x);
}
if (b[i] == a[i].z) {
maxx = max(maxx, ans + sum2[i - 1] * a[i].x - sum3[i - 1]);
}
}
cout << maxx << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7724kb
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: 5680kb
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'