QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685450 | #9529. Farm Management | wzl19371# | WA | 0ms | 3660kb | C++14 | 2.0kb | 2024-10-28 19:29:59 | 2024-10-28 19:30:00 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i, o, p) for(int i = o; i <= p; i ++ )
using namespace std;
typedef long long ll;
constexpr int maxn = 1e5+10;
ll n,m,sl[maxn],sr[maxn],ansrs[maxn],ansls[maxn];
struct Crop {
int l, r;
ll w;
bool operator<(const Crop& rhs)const {
return w > rhs.w;
}
}a[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
rep(i,1,n) cin >> a[i].w >> a[i].l >> a[i].r;
sort(a+1, a+1+n);
rep(i,1,n) sl[i] = sl[i-1] + a[i].l;
rep(i,1,n) sr[i] = sr[i-1] + a[i].r;
rep(i,1,n) ansrs[i] = ansrs[i-1] + a[i].r * a[i].w;
rep(i,1,n) ansls[i] = ansls[i-1] + a[i].l * a[i].w;
ll ansi = 0;
ll timec = sl[n];
rep(i,1,n) ansi += a[i].l * a[i].w;
int sep = -1;
rep(i,1,n) {
ll tmp = min(m - timec, 1ll * (a[i].r - a[i].l));
ansi += a[i].w * tmp;
timec += tmp;
if(timec == m) {
sep = i;
break;
}
}
ll ans = ansi;
if(sep == -1) {
cout << ans << endl;
return 0;
}
ll ansl = 0;
rep(i,1,n) {
ansl += a[i].l * a[i].w;
}
rep(i,1,n) {
ans = max(ans, ansl - a[i].l * a[i].w + (m - (sl[n] - a[i].l)) * a[i].w);
}
rep(i,sep+1,n) {
if(sr[i-1] <= m - a[i].l)
continue;
int l=0, r=i-1, mid, as;
while(l <= r) {
mid = (l + r) >> 1;
if(m - (sl[n] - sl[mid]) + a[i].l - sr[mid-1] >= 0) {
as = mid;
l = mid + 1;
}else{
r = mid - 1;
}
}
ll asct = min(m - (sl[n] - sl[as]) + a[i].l - sr[as-1], 1ll * a[as].r);
ll ict = m - (sl[n] - sl[as]) + a[i].l - sr[as-1] - asct;
ans = max(ans, ansrs[as - 1] + (ansls[n] - ansls[as]) - a[i].l * a[i].w + asct * a[as].w + a[i].w * ict);
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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: 3600kb
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:
37012231
result:
wrong answer 1st lines differ - expected: '35204500', found: '37012231'