https://www.acmicpc.net/problem/1590
#include<stdio.h>
int main() {
int n,t;
scanf("%d %d",&n,&t);
int count=-1;
int min=10000000;
int sum=0;
for(int i=0;i<n;i++){
int si,li,ci;
scanf("%d %d %d",&si,&li,&ci);
sum=si;
for(int j=0;j<ci;j++){
if(t<=sum){
count=sum-t;
break;
}
sum+=li;
}
if(count<=min && count!=-1) min=count;
}
if(count==-1) printf("%d",count);
else printf("%d",min);
}