-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2980.cpp
More file actions
51 lines (48 loc) · 747 Bytes
/
2980.cpp
File metadata and controls
51 lines (48 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 2980. 도로와 신호등
// 2019.05.21
// 시뮬레이션
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
// 신호등 구조체
struct light
{
int d;
int r;
int g;
int sum = r + g;
};
vector<light> v;
int main()
{
int n, l;
cin >> n >> l;
for (int i = 0; i < n; i++)
{
int d, r, g;
cin >> d >> r >> g;
v.push_back({ d,r,g });
}
int cnt = 0; // 상근이 위치
int sec = 0; // 총 시간
while (cnt < l)
{
for (int i = 0; i < n; i++)
{
// 상근이가 신호등이 있는곳에 있을때
if (v[i].d == cnt)
{
// 빨간불일때
if (sec%v[i].sum <= v[i].r)
{
sec += v[i].r - sec % v[i].sum;
}
}
}
sec++;
cnt++;
}
cout << sec << endl;
return 0;
}