Submission #614918

# Submission time Handle Problem Language Result Execution time Memory
614918 2022-07-31T05:31:58 Z 반딧불(#8492) Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1196 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int q, l;
vector<pair<int, int> > ant, sugar;

void solve(){
    vector<pair<int, int> > ant = ::ant, sugar = ::sugar;
    sort(ant.begin(), ant.end());
    sort(sugar.begin(), sugar.end());
    int i = 0, j = 0;
    ll ans = 0;
    for(; i<(int)ant.size() && j<(int)sugar.size(); i++){
        while(j<(int)sugar.size() && sugar[j].first < ant[i].first - l) j++;
        if(j==(int)sugar.size()) break;
        while(j<(int)sugar.size() && (ant[i].second && sugar[j].first <= ant[i].first + l)){
            ll tmp = min(ant[i].second, sugar[j].second);
            ant[i].second -= tmp, sugar[j].second -= tmp;
            ans += tmp;
            if(!sugar[j].second) j++;
        }
    }
    printf("%lld\n", ans);
}

int main(){
    scanf("%d %d", &q, &l);
    for(int qc=1; qc<=q; qc++){
        int t, x, y;
        scanf("%d %d %d", &t, &x, &y);
        if(t==1) ant.push_back(make_pair(x, y));
        else sugar.push_back(make_pair(x, y));
        solve();
    }
}

Compilation message

sugar.cpp: In function 'int main()':
sugar.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d %d", &q, &l);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sugar.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d %d %d", &t, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 120 ms 412 KB Output is correct
7 Correct 75 ms 412 KB Output is correct
8 Correct 21 ms 392 KB Output is correct
9 Correct 19 ms 340 KB Output is correct
10 Correct 227 ms 424 KB Output is correct
11 Correct 220 ms 480 KB Output is correct
12 Correct 240 ms 576 KB Output is correct
13 Correct 244 ms 612 KB Output is correct
14 Correct 237 ms 440 KB Output is correct
15 Correct 244 ms 460 KB Output is correct
16 Correct 241 ms 584 KB Output is correct
17 Correct 225 ms 416 KB Output is correct
18 Correct 235 ms 420 KB Output is correct
19 Correct 225 ms 468 KB Output is correct
20 Correct 220 ms 444 KB Output is correct
21 Correct 237 ms 460 KB Output is correct
22 Correct 229 ms 444 KB Output is correct
23 Correct 241 ms 580 KB Output is correct
24 Correct 231 ms 432 KB Output is correct
25 Correct 245 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 4058 ms 1196 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 4061 ms 996 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 120 ms 412 KB Output is correct
7 Correct 75 ms 412 KB Output is correct
8 Correct 21 ms 392 KB Output is correct
9 Correct 19 ms 340 KB Output is correct
10 Correct 227 ms 424 KB Output is correct
11 Correct 220 ms 480 KB Output is correct
12 Correct 240 ms 576 KB Output is correct
13 Correct 244 ms 612 KB Output is correct
14 Correct 237 ms 440 KB Output is correct
15 Correct 244 ms 460 KB Output is correct
16 Correct 241 ms 584 KB Output is correct
17 Correct 225 ms 416 KB Output is correct
18 Correct 235 ms 420 KB Output is correct
19 Correct 225 ms 468 KB Output is correct
20 Correct 220 ms 444 KB Output is correct
21 Correct 237 ms 460 KB Output is correct
22 Correct 229 ms 444 KB Output is correct
23 Correct 241 ms 580 KB Output is correct
24 Correct 231 ms 432 KB Output is correct
25 Correct 245 ms 460 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Execution timed out 4058 ms 1196 KB Time limit exceeded
30 Halted 0 ms 0 KB -