QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707003 | #9529. Farm Management | the_foo# | WA | 0ms | 3528kb | C++20 | 1.7kb | 2024-11-03 14:18:34 | 2024-11-03 14:18:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define int LL
using LL = long long;
void solve() {
int n,m;
cin>>n>>m;
vector<pair<int,pair<int,int> > >vp(n+1);
for(int i=0;i<n;i++)cin>>vp[i].fi>>vp[i].se.fi>>vp[i].se.se;
sort(vp.begin(),vp.end());
int r1 = 0;
int _ = m;
for(int i=1;i+1<vp.size();i++) {
r1 += vp[i].se.fi * vp[i].fi;
_ -= vp[i].se.fi;
}
r1 += vp.back().fi * _;
vector<int> ll(n+1), rr(n+1);
vector<int> lll(n+1), rrr(n+1);
for(int i=1;i<=n;i++) {
ll[i] = ll[i-1] + vp[i].se.fi;
rr[i] = rr[i-1] + vp[i].se.se;
lll[i] = lll[i-1] + vp[i].se.fi * vp[i].fi;
rrr[i] = rrr[i-1] + vp[i].se.se * vp[i].fi;
}
for(int i=1;i+1<n;i++) {
int l = i;
int r = n+1;
int d = vp[i].se.fi;
while(l+1 < r) {
int mid = (l+r)/2;
int ss = 0;
ss += ll[mid-1];
ss += rr[n] - rr[mid];
if(i < mid) ss -= ll[i];
if(m-ss > vp[i].se.se)r = mid;
else l = mid;
}
// l 居中的位置
int rrrr = 0;
rrrr += lll[l-1];
rrrr += rrr[n] - rrr[l];
int ss = 0;
ss += ll[l-1];
ss += rr[n] - rr[l];
if(l != i) {
ss -= vp[i].se.fi;
rrrr -= vp[i].se.fi * vp[i].fi;
}
rrrr += (m-ss) * vp[l].fi;
r1 = max(rrrr,r1);
}
cout<<r1<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3492kb
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: 3528kb
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:
38379035
result:
wrong answer 1st lines differ - expected: '35204500', found: '38379035'