# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
906703 | vjudge1 | Ants and Sugar (JOI22_sugar) | C++17 | 4062 ms | 1916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define NN
#define M 1000000007 // 998244353
ll L;
ll solve(vector<pl> ants, vector<pl> sugars) {
ll ans = 0;
ll ap = 0, sp = 0;
while (ap < ants.size() and sp < sugars.size()) {
if (!ants[ap].V) {
++ap; continue;
}
if (!sugars[sp].V) {
++sp; continue;
}
ll left = ants[ap].K - L, right = ants[ap].K + L;
if (left <= sugars[sp].K and sugars[sp].K <= right) {
ll sub = min(ants[ap].V, sugars[sp].V);
ants[ap].V -= sub;
sugars[sp].V -= sub;
ans += sub;
continue;;
} else if (right < sugars[sp].K) ap++;
else sp++;
}
return ans;
}
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
G(q) cin >> L;
vector<pl> ants, sugars;
while (q--) {
G(t) G(x) G(a)
(t == 1 ? ants: sugars).emplace_back(x, a);
sort(A(ants)); sort(A(sugars));
cout << solve(ants, sugars) << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |