File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = int64_t ;
5
+ using ff = long double ;
6
+
7
+ int N, C;
8
+ vector<int > as, bs, cs;
9
+
10
+ ll solve () {
11
+ vector<pair<int ,int >> events;
12
+ for (int i = 0 ; i < N; ++i) {
13
+ events.push_back (make_pair (as[i], cs[i]));
14
+ events.push_back (make_pair (bs[i]+1 , -cs[i]));
15
+ }
16
+ sort (events.begin (), events.end ());
17
+
18
+ int time = 0 ;
19
+ ll charge_per_day = 0 ;
20
+ ll total_charge = 0 ;
21
+ for (auto const & event : events) {
22
+ int t, charge;
23
+ tie (t, charge) = event;
24
+ total_charge += (t - time) * min (ll (C), charge_per_day);
25
+ charge_per_day += charge;
26
+ time = t;
27
+ }
28
+ return total_charge;
29
+ }
30
+
31
+ int main () {
32
+ ios_base::sync_with_stdio (false );
33
+ cin.tie (0 ); cout.tie (0 );
34
+
35
+ cin >> N >> C;
36
+ as.assign (N, 0 );
37
+ bs.assign (N, 0 );
38
+ cs.assign (N, 0 );
39
+ for (int i = 0 ; i < N; ++i) {
40
+ cin >> as[i] >> bs[i] >> cs[i];
41
+ }
42
+ cout << solve () << endl;
43
+
44
+ return 0 ;
45
+ }
You can’t perform that action at this time.
0 commit comments