QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#779800 | #9529. Farm Management | Sunwking | WA | 0ms | 3544kb | C++20 | 1.6kb | 2024-11-24 21:50:02 | 2024-11-24 21:50:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void solved(){
LL n , m;
cin >> n >> m;
vector<array<LL , 3>> a(n + 1);
for(int i = 1 ; i <= n ; i ++ )
for(int j = 0 ; j < 3 ; j ++ )
cin >> a[i][j];
std::sort(a.begin() + 1, a.end() , [&](auto a , auto b){
return a[0] > b[0];
});
vector<LL> R(n + 10) , L(n + 10) , l(n + 10) , r(n + 10);
for(int i = 1 ; i <= n ; i ++ )
R[i] = R[i - 1] + a[i][2] * a[i][0] , r[i] = r[i - 1] + a[i][2];
for(int i = n ; i ; i -- )
L[i] = L[i + 1] + a[i][1] * a[i][0] , l[i] = l[i + 1] + a[i][1];
LL ans = 0;
for(int i = 1 ; i <= n ; i ++ ){
LL sum = l[i + 1] + r[i - 1];
if(sum <= m){
ans = max(ans , L[i + 1] + R[i - 1] + (m - sum) * a[i][0]);
}else {
int l1 = 1 , r1 = i - 1;
LL k = m - l[i + 1];
while(l1 <= r1){
int mid = (l1 + r1) >> 1;
LL s = r[mid - 1] + l[mid + 1] - l[i];
if(s > k) r1 = mid - 1;
else if(k - s <= a[mid][2] && k - s >= a[mid][1]) {
ans = max(ans , R[mid - 1] + L[mid + 1] - a[i][0] * a[i][1] + (k - s) * a[mid][0]);
break;
}else l1 = mid + 1;
}
}
// cout << ans << "\n";
}
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t -- )
solved();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
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: 3544kb
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:
34859047
result:
wrong answer 1st lines differ - expected: '35204500', found: '34859047'