QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692470 | #9529. Farm Management | emt# | WA | 0ms | 3684kb | C++20 | 1.9kb | 2024-10-31 14:34:07 | 2024-10-31 14:34:09 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
using i128 = __int128_t;
using u128 = __uint128_t;
using ld = long double;
using i64 = long long;
using pi = pair<int,int>;
#define mem(a, b) memset((a), (b), sizeof(a))
#define all(a) (a).begin(), (a).end()
#define lowbit(x) (-x)&x
#define ls u<<1
#define rs u<<1|1
mt19937 rnd(time(0));
const i64 mod = 1e9+7;
const i64 N = 1e3+7;
const i64 inf = 1e18+7;
i64 qmi(i64 m, i128 k,i64 p = mod){i128 res = 1, t = m;while (k){if (k & 1) res = (res * t) % p;t = t * t % p;k >>= 1;}return res;}
i64 inv(i64 u){return qmi(u,mod-2);}
void solve()
{
int n,m;cin>>n>>m;
vector<array<int,3>> a(n);
vector<int> pre(n+1);
for(auto &[c,d,e]:a) cin>>c>>d>>e;
sort(all(a));
for(int i=1;i<=n;i++)
pre[i] = pre[i-1] + a[i-1][1];
int ans = 0, tot = 0;
for(int i=1;i<=n;i++)
tot += a[i-1][1] * a[i-1][0];
deque<array<int,2>> q;
int me = m;
for(int i=n;i>=1;i--)
{
if(i!=n)
q.push_back({a[i][0],a[i][2]});
tot -= a[i-1][0] * a[i-1][1];
while(me-pre[i-1] > 0 && q.size())
{
auto [w,num] = q.front(); q.pop_front();
if(num<=me-pre[i-1])
{
me -= num;
tot += num * w;
num = 0;
}
else
{
num -= me-pre[i-1];
tot += (me-pre[i-1]) * w;
me = pre[i-1];
}
if(num)
q.push_front({w,num});
}
ans = max(ans, tot + (me-pre[i-1])*a[i-1][0]);
}
cout<<ans<<"\n";
}
signed main()
{
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T = 1;
// cin>>T;
while(T--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3684kb
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: 3680kb
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'