比赛 |
4043级2023省选模拟赛6 |
评测结果 |
AAAAAAAAAAW |
题目名称 |
Bakery |
最终得分 |
90 |
用户昵称 |
yrtiop |
运行时间 |
0.562 s |
代码语言 |
C++ |
内存使用 |
3.65 MiB |
提交时间 |
2023-03-28 09:56:03 |
显示代码纯文本
#include <bits/stdc++.h>
using i64 = long long;
const int maxn = 105;
int n;
i64 x,y,a[maxn],b[maxn],c[maxn];
i64 calc(i64 k) {
i64 cur = 1e18;
for(int i = 1;i <= n;++ i)
cur = std::min(cur , (c[i] - a[i] * k) / b[i]);
if(cur >= 1)
return x - k + std::max(0ll , y - cur);
else
return 1e18;
}
void work() {
scanf("%d %lld %lld",&n,&x,&y);
i64 lim = 1e18;
for(int i = 1;i <= n;++ i)
scanf("%lld %lld %lld",&a[i],&b[i],&c[i]),lim = std::min(lim , (c[i] - b[i]) / a[i]);
i64 l = 1,r = std::min(x , lim);
i64 ans = 1e18;
while(l <= r) {
if(r - l <= 1000) {
for(i64 k = l;k <= r;++ k)
ans = std::min(ans , calc(k));
break ;
}
i64 flac = (2ll * l + r) / 3,frac = (l + 2ll * r) / 3;
if(calc(flac) > calc(frac))
l = flac;
else
r = frac;
}
printf("%lld\n",ans);
return ;
}
int main() {
freopen("bakery.in","r",stdin);
freopen("bakery.out","w",stdout);
int T;
scanf("%d",&T);
while(T --)
work();
return 0;
}