#include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cmplx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound((v).begin(), (v).end(), x) - (v).begin())
#define ubv(v, x) (upper_bound((v).begin(), (v).end(), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cout << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cout << #arr; FR(_i, n) cout << ' ' << arr[_i]; cout << endl;}
int q, l;
int main(){
boost();
cin >> q >> l;
vpii arr, brr;
while(q--){
int t, x, a;
cin >> t >> x >> a;
if(t == 1) arr.insert(lower_bound(ALL(arr), pii{x, -1}), pii{x, a});
if(t == 2) brr.insert(lower_bound(ALL(brr), pii{x, -1}), pii{x, a});
vpii acpy = arr, bcpy = brr;
ll res = 0;
int asz = SZ(arr), bsz = SZ(brr);
int i = 0, j = 0;
while(i < asz && j < bsz){
if(abs(arr[i].fs - brr[j].fs) <= l){
int mn = min(arr[i].sn, brr[j].sn);
res += mn;
arr[i].sn -= mn, brr[j].sn -= mn;
if(!arr[i].sn) i++;
if(!brr[j].sn) j++;
}
else if(arr[i].fs < brr[j].fs) i++;
else j++;
}
arr = acpy, brr = bcpy;
cout << res << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
452 KB |
Output is correct |
7 |
Correct |
11 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
26 ms |
468 KB |
Output is correct |
11 |
Correct |
31 ms |
492 KB |
Output is correct |
12 |
Correct |
35 ms |
520 KB |
Output is correct |
13 |
Correct |
35 ms |
484 KB |
Output is correct |
14 |
Correct |
11 ms |
468 KB |
Output is correct |
15 |
Correct |
17 ms |
468 KB |
Output is correct |
16 |
Correct |
17 ms |
468 KB |
Output is correct |
17 |
Correct |
11 ms |
464 KB |
Output is correct |
18 |
Correct |
10 ms |
468 KB |
Output is correct |
19 |
Correct |
22 ms |
492 KB |
Output is correct |
20 |
Correct |
10 ms |
432 KB |
Output is correct |
21 |
Correct |
43 ms |
504 KB |
Output is correct |
22 |
Correct |
11 ms |
472 KB |
Output is correct |
23 |
Correct |
48 ms |
468 KB |
Output is correct |
24 |
Correct |
11 ms |
456 KB |
Output is correct |
25 |
Correct |
48 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Execution timed out |
4038 ms |
2564 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
4067 ms |
3536 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
452 KB |
Output is correct |
7 |
Correct |
11 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
26 ms |
468 KB |
Output is correct |
11 |
Correct |
31 ms |
492 KB |
Output is correct |
12 |
Correct |
35 ms |
520 KB |
Output is correct |
13 |
Correct |
35 ms |
484 KB |
Output is correct |
14 |
Correct |
11 ms |
468 KB |
Output is correct |
15 |
Correct |
17 ms |
468 KB |
Output is correct |
16 |
Correct |
17 ms |
468 KB |
Output is correct |
17 |
Correct |
11 ms |
464 KB |
Output is correct |
18 |
Correct |
10 ms |
468 KB |
Output is correct |
19 |
Correct |
22 ms |
492 KB |
Output is correct |
20 |
Correct |
10 ms |
432 KB |
Output is correct |
21 |
Correct |
43 ms |
504 KB |
Output is correct |
22 |
Correct |
11 ms |
472 KB |
Output is correct |
23 |
Correct |
48 ms |
468 KB |
Output is correct |
24 |
Correct |
11 ms |
456 KB |
Output is correct |
25 |
Correct |
48 ms |
476 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
316 KB |
Output is correct |
29 |
Execution timed out |
4038 ms |
2564 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |