mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
54568ca2fa
4700-4799
45 lines
910 B
C++
45 lines
910 B
C++
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
#define ll __int64
|
|
#define L 20005
|
|
ll a[L],b[L],c[L],l,r,n;
|
|
ll solve(ll mid)
|
|
{
|
|
ll k,sum = 0;
|
|
int i;
|
|
for(i = 0; i<n; i++)
|
|
{
|
|
k = min(mid,b[i]);
|
|
if(k>=a[i])
|
|
sum+=(k-a[i])/c[i]+1;
|
|
}
|
|
return sum;
|
|
}
|
|
int main()
|
|
{
|
|
int i,j;
|
|
while(~scanf("%d",&n))
|
|
{
|
|
for(i = 0; i<n; i++)
|
|
scanf("%I64d%I64d%I64d",&a[i],&b[i],&c[i]);
|
|
l = 0,r = 1LL<<31;
|
|
ll mid;
|
|
while(l<r)
|
|
{
|
|
mid = (l+r)/2;
|
|
if(solve(mid)%2) r = mid;
|
|
else l = mid+1;
|
|
}
|
|
if(l == 1LL<<31)
|
|
printf("DC Qiang is unhappy.\n");
|
|
else
|
|
{
|
|
while(solve(l)%2==0)l--;
|
|
printf("%I64d %I64d\n",l,solve(l)-solve(l-1));
|
|
}
|
|
}
|
|
return 0;
|
|
}
|