https://www.acmicpc.net/problem/1590
using System;
class Program
{
static void Main() {
string[] s=Console.ReadLine().Split(' ');
int n=int.Parse(s[0]);
int t=int.Parse(s[1]);
int count=-1;
int min=10000000;
int sum=0;
for(int i=0;i<n;i++){
string[] s1=Console.ReadLine().Split(' ');
int si=int.Parse(s1[0]);
int li=int.Parse(s1[1]);
int ci=int.Parse(s1[2]);
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) Console.Write(count);
else Console.Write(min);
}
}