boj1590_캠프가는 영식
#include<iostream>
using namespace std;
struct Node {
int start, interval, cnt;
};
Node node[100000];
int min(int a, int b) {
return a >= b ? b : a;
}
int main() {
int n, t;
scanf("%d %d",&n,&t);
int ans = 1e9;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &node[i].start, &node[i].interval, &node[i].cnt);
int restTime = t - node[i].start, restCnt = restTime / node[i].interval;
int cnt = restTime % node[i].interval <= 0 ? restCnt : restCnt + 1;
if (cnt < 0) cnt = 0;
if (cnt<node[i].cnt) {//5 5 3 5
ans = min(ans, (cnt*node[i].interval) + node[i].start -t);
}
}
if (ans == 1e9) printf("-1");
else printf("%d", ans);
}