QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685594 | #9529. Farm Management | megumi# | WA | 1ms | 7720kb | C++17 | 2.3kb | 2024-10-28 20:21:24 | 2024-10-28 20:21:27 |
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;
}
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 = n + 1;
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";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7720kb
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: 0
Accepted
time: 1ms
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:
35204500
result:
ok single line: '35204500'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7704kb
input:
15 32 835418 2 3 178262 1 3 527643 2 2 519710 1 1 774544 3 3 82312 1 1 808199 1 1 809396 1 3 255882 1 3 80467 1 3 874973 1 3 813965 1 2 198275 1 2 152356 1 3 802055 1 1
output:
22000255
result:
ok single line: '22000255'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5680kb
input:
13 20 526447 1 1 807398 2 2 4167 1 2 944031 2 2 830685 2 2 394251 1 2 505011 1 2 968848 1 1 58170 1 3 32504 1 1 792273 3 3 196120 1 2 714507 1 1
output:
12032287
result:
wrong answer 1st lines differ - expected: '12878768', found: '12032287'