QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743229 | #9529. Farm Management | abovecloud | RE | 0ms | 0kb | C++14 | 1.4kb | 2024-11-13 18:38:12 | 2024-11-13 18:38:16 |
answer
/*Time:2024-11-13 16:49:25*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define second se
#define first fi
#define vi vector<int>
#define vvi vector<vi>
#define all(v) v.begin(),v.end()
const int MOD = (int) 1e9 + 7;
const int INF = INT_MAX;
const int MAXN = 1e5+5;
struct node{
int w,l,r;
const bool operator<(const node& b){
return w>b.w;
}
}a[MAXN];
void solve() {
int n,m;
cin >> n >> m;
for(int i = 1;i<=n;i++){
cin >> a[i].w >> a[i].l >> a[i].r;
}
int c1 = 0,c2=0;
sort(a+1,a+n+1);
vi use(n,0);
vi dp1(n,0);
vi dp2(n,0);
int base = 0;
for(int i = 1;i<=n;i++){
base += a[i].l * a[i].w;
m-=a[i].l;
use[i] += a[i].l;
dp1[i] = (a[i].r - a[i].l) + dp1[i-1];
dp2[i] = (a[i].r - a[i].l) * a[i].w + dp2[i-1];
}
int ans = base;
for(int i = 1;i<=n;i++){
int cur = base - a[i].l*a[i].w;
m += a[i].l;
int l=1,r=i-1,res=0;
while(l<=r){
int mid = l + r >> 1;
if(m >= dp1[mid]){
res = mid;
l = mid + 1;
}else{
r = mid - 1;
}
}
cur += (m-dp1[res])*a[res+1].w + dp2[res];
ans = max(ans,cur);
m -= a[i].l;
}
cout << ans << endl;
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(12);
int T = 1;
// cin >> T;
while (T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
109