QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720770 | #9529. Farm Management | LeoG | WA | 0ms | 3824kb | C++23 | 3.5kb | 2024-11-07 14:02:21 | 2024-11-07 14:02:21 |
Judging History
answer
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#define ll long long
#define all(v) v.begin(),v.end()
#define ld long double
#define pll std::pair<ll,ll>
#define pi std::pair<int,int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define len(x) (int)x.size()
#define vec(T) std::vector<T>
template<typename T, typename = void>
struct is_printable : std::false_type {};
template<typename T>
struct is_printable<T, std::void_t<decltype(std::declval<std::ostream&>() << std::declval<T>())>> : std::true_type {};
template <typename T>
void print(const std::pair<T, T>& pair) {
std::cout << "(" << pair.first << ", " << pair.second << ")";
}
// General print function
template <typename T>
void print(const T& val) {
std::cout << val;
}
// Print function for std::vector
template <typename T>
void print(const std::vector<T>& vec) {
std::cout << '[';
int n = vec.size();
for (int i = 0; i < n; i++) {
print(vec[i]);
if (i < n - 1) {
std::cout << ",";
}
}
std::cout << ']' << '\n';
}
// Variadic template print function
template<typename T, typename... Args>
void print(const T& t, const Args&... args) {
print(t);
std::cout << (is_printable<T>::value ? ' ' : '\0');
print(args...);
if (sizeof...(args) == 1 && is_printable<T>::value) std::cout << '\n';
}
struct Crop {
ll w, l, r;
};
void solve(){
ll n, m, cnt = 0, sum = 0;
std::cin >> n >> m;
vec(Crop) crop(n);
vll t(n), lcnt(n + 1), lsum(n + 1), rcnt(n + 1), rsum(n + 1), tcnt(n + 1), tsum(n + 1);
for (int i = 0; i < n; i++) {
std::cin >> crop[i].w >> crop[i].l >> crop[i].r;
cnt += crop[i].r;
sum += crop[i].w * crop[i].r;
}
std::sort(all(crop), [](const Crop& a, const Crop& b){return a.w > b.w;});
for (int i = 0; i < n; i++) {
t[i] = crop[i].r;
}
for (int i = n - 1; i >= 0 && cnt > m; i--) {
ll tmp = std::min(cnt - m, crop[i].r - crop[i].l);
cnt -= tmp;
sum -= tmp * crop[i].w;
t[i] -= tmp;
}
for (int i = 0; i < n; i++) {
lcnt[i + 1] = lcnt[i] + crop[i].l;
tcnt[i + 1] = tcnt[i] + t[i];
rcnt[i + 1] = rcnt[i] + crop[i].r;
lsum[i + 1] = lsum[i] + crop[i].l * crop[i].w;
tsum[i + 1] = tsum[i] + t[i] * crop[i].w;
rsum[i + 1] = rsum[i] + crop[i].r * crop[i].w;
}
ll ans = tsum[n];
for (int i = 0; i < n; i++) {
if (t[i] == crop[i].r) {
ll cnt = tcnt[n] - tcnt[i + 1] - lcnt[n] + lcnt[i + 1];
ans = std::max(ans, tsum[i + 1] + lsum[n] - lsum[i + 1] + cnt * crop[i].w);
}
else {
int l = 0, r = i + 1;
while (l < r) {
int m = (l + r) / 2;
if (rcnt[m] - tcnt[m] < t[i]) {
l = m + 1;
}
else {
r = m;
}
}
ll tmp = rsum[l] - tsum[l];
ans = std::max(ans, tsum[n] + tmp - (rcnt[l] - tcnt[l]) * crop[i].w);
}
}
std::cout << ans << std::endl;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//std::cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
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: 3744kb
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:
35845915
result:
wrong answer 1st lines differ - expected: '35204500', found: '35845915'