-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cashier.cpp
83 lines (60 loc) · 1.16 KB
/
Cashier.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Cashier
// https://codeforces.com/problemset/problem/1059/A
// Aman Kumar
/*
INSIGHT:
-
*/
#include <bits/stdc++.h>
using namespace std ;
#define ll long long int
#define ss second
#define ff first
void mandalore() ;
int main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
int t = 1 ;
//cin >> t ;
while( t-- ) mandalore() ;
return 0 ;
}
void mandalore()
{
ll n, l, a ;
cin >> n >> l >> a ;
vector<int> timing(n) ;
vector<int> serve(n) ;
ll count = 0 ;
if( n > 0 )
{
for( int i = 0 ; i < n ; i++ )
{
cin >> timing[i] >> serve[i] ;
}
vector<pair<int,int>> busy ;
for( int i = 0 ; i < n ; i++ )
{
int start = timing[i] ;
int end = start + serve[i] ;
busy.push_back( make_pair( start, end ) ) ;
}
// Before first customer arrives
count += ( busy[0].first / a ) ;
// Between customer's arriving
for( int i = 1 ; i < busy.size() ; i++ )
{
int diff = busy[i].first - busy[i-1].second ;
count += ( diff / a ) ;
}
// After last customer
int diff = l - busy[ busy.size()- 1 ].second ;
count += ( diff / a ) ;
}
else
{
count += ( l / a ) ;
}
cout << count << "\n" ;
}