比赛 4043级2023省选模拟赛6 评测结果 AAAAAAAAAAA
题目名称 Bakery 最终得分 100
用户昵称 op_组撒头屯 运行时间 0.007 s
代码语言 C++ 内存使用 1.04 MiB
提交时间 2023-03-28 10:32:55
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll __int128
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=100+5;
int n;
ll x,y,a[N],b[N],c[N];
ll read(){
    ll ans=0;char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return ans;
}
void write(ll x){
    if (x<0)putchar('-'),x=-x;
    if (x>9)write(x/10);
    putchar(x%10+'0');
}
bool chck(ll mid){
    ll l=0,r=y-1;
    for (int i=1;i<=n;i++){
        ll now=c[i]-a[i]*mid,re=b[i]-a[i];
        if (!re&&now>0)return 0;
        if (re>0)l=max(l,(ll)ceil(1.0*now/re));
        if (re<0)r=min(r,(ll)floor(1.0*now/re));
        if (l>r)return 0;
    }
    if (mid-l<0||x-1<mid-r)return 0;
    return 1;
}

int main(){
	freopen ("bakery.in","r",stdin);
	freopen ("bakery.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--){
		scanf("%d",&n);x=read();y=read();
		for (int i=1;i<=n;i++){
		    a[i]=read();b[i]=read();c[i]=read();
		    c[i]=a[i]*x+b[i]*y-c[i];
        }
		ll l=0,r=x+y-2;
		while(l<r){
		    ll mid=(l+r)/2;
		    if (chck(mid))r=mid;
		    else l=mid+1;
        }
        write(l);putchar('\n');
	}
}