QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687419 | #9529. Farm Management | wangxi527# | WA | 0ms | 3780kb | C++17 | 1.4kb | 2024-10-29 18:55:55 | 2024-10-29 18:55:55 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct Q {
int w , l , r ;
inline bool operator <(const Q &x) const {
return w > x.w ;
}
};
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n , m ; cin >> n >> m ;
vector<Q> a(n) ;
for(int i = 0 ; i < n ; i ++ ) cin >> a[i].w >> a[i].l >> a[i].r ;
sort(all(a)) ;
int ans = 0 , now = 0;
queue<pii> q ;
for(int i = 0 ; i < n ; i ++ ) {
ans += a[i].w * a[i].l; a[i].r -= a[i].l ;
now += a[i].l ;
q.push({a[i].w,a[i].r}) ;
}
while(q.size() && now < m) {
auto x = q.front() ;
if(x.second <= m - now) {
ans += x.second * x.first ;
now += x.second ; q.pop() ;
}
else {
ans += (m - now) * x.first ;
q.front().second -= m - now ;
now = m ; break ;
}
}
int res = ans ;
for(int i = n - 1 ; i >= 0 ; i -- ) {
if(q.empty()) break ;
res -= a[i].l * a[i].w;
now -= a[i].l ;
while(q.size() && now < m) {
auto x = q.front() ;
if(x.second <= m - now) {
res += x.second * x.first ;
now += x.second ; q.pop() ;
}
else {
res += (m - now) * x.first ;
q.front().second -= m - now ;
now = m ; break ;
}
}
if(now == m)
ans = max(ans,res) ;
}
cout << ans << endl ;
return 0 ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 3780kb
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:
40106857
result:
wrong answer 1st lines differ - expected: '35204500', found: '40106857'