QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692703 | #9529. Farm Management | konbi# | WA | 0ms | 3812kb | C++20 | 2.2kb | 2024-10-31 14:55:39 | 2024-10-31 14:55:47 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
#define pb push_back
#define ls (u << 1)
#define rs (u << 1 | 1)
typedef long long LL;
typedef pair<int, int> PII;
// #define debug(args...) {}
#define debug(args...) { \
string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << ' ';
err(++it, args...);
}
void solve() {
LL n, m;
cin >> n >> m;
vector<array<LL, 3>> a(n + 5);
for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
sort(a.begin() + 1, a.begin() + n + 1, [&](auto x, auto y)->int{
return x[0] < y[0];
});
LL res = 0, now = 0, nd = m;
for (int i = 1; i <= n; i++) {
now += a[i][0] * a[i][1];
nd -= a[i][1];
}
res = now + nd * a[n][0]; // case 1
vector<LL> sum(n + 5), val(n + 5);
for (int i = 1; i <= n; i++) {
auto [w, l, r] = a[i];
sum[i] = sum[i - 1] + r - l;
val[i] = val[i - 1] + (r - l) * w;
}
auto cal = [&](int ban)->LL {
int l = ban + 1, r = n;
while (l < r) {
int mid = l + r >> 1;
if (sum[n] - sum[mid - 1] <= nd) r = mid;
else l = mid + 1;
}
int mid = l;
LL rd = nd - (sum[n] - sum[mid - 1]);
LL ret = val[n] - val[mid - 1];
ret += a[mid - 1][0] * rd;
// cerr << ban << ' ' << mid << ' ' << rd << ' ' << ret << ' ' << now << "\n";
// debug(sum[1], sum[2], sum[3], sum[4]);
return ret + now;
};
res = max(res, cal(0));
for (int i = 1; i <= n; i++) {
nd += a[i][1]; now -= a[i][0] * a[i][1];
res = max(res, cal(i));
nd -= a[i][1]; now += a[i][0] * a[i][1];
}
cout << res << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1; //cin >> tt;
while (tt--) solve();
return 0;
}
/*
g++ std.cpp -Wall --extra -o std && ./std < in.txt > out.txt
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 3560kb
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:
35309054
result:
wrong answer 1st lines differ - expected: '35204500', found: '35309054'