제출 #906703

#제출 시각아이디문제언어결과실행 시간메모리
906703vjudge1Ants and Sugar (JOI22_sugar)C++17
6 / 100
4062 ms1916 KiB
#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;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

sugar.cpp: In function 'll solve(std::vector<std::pair<long long int, long long int> >, std::vector<std::pair<long long int, long long int> >)':
sugar.cpp:30:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (ap < ants.size() and sp < sugars.size()) {
      |            ~~~^~~~~~~~~~~~~
sugar.cpp:30:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (ap < ants.size() and sp < sugars.size()) {
      |                                 ~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...