Submission #877806

#TimeUsernameProblemLanguageResultExecution timeMemory
877806vjudge1Ants and Sugar (JOI22_sugar)C++17
6 / 100
4074 ms1344 KiB
// https://oj.uz/problem/view/JOI22_sugar

#include <bits/stdc++.h>
using namespace std;

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);

        int q, L;
        cin >> q >> L;
        vector<pair<int, int>> ant, sugar;
        while (q--) {
                int t, a, x;
                cin >> t >> x >> a;
                auto& which = t == 1 ? ant : sugar;
                which.emplace_back(x, a);
                sort(which.begin(), which.end());
                int j = 0;
                int64_t remain = sugar.size() ? sugar[0].second : -1;
                int64_t res = 0;
                for (int i = 0; i < ant.size(); i++) {
                        int64_t total_ants = ant[i].second;
                        while (j < sugar.size() && sugar[j].first < ant[i].first - L) j++, remain = j < sugar.size() ? sugar[j].second : -1;
                        while (j < sugar.size() && (sugar[j].first - ant[i].first) <= L && total_ants > 0) {
                                int64_t take = min(total_ants, remain);
                                res += take;
                                if (remain <= take) {
                                        total_ants -= remain;
                                        j++;
                                        remain = remain = j < sugar.size() ? sugar[j].second : -1;
                                } else {
                                        total_ants = 0;
                                        remain -= take;
                                }
                        }
                }
                cout << res << '\n';
        }
}

Compilation message (stderr)

sugar.cpp: In function 'int32_t main()':
sugar.cpp:22:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |                 for (int i = 0; i < ant.size(); i++) {
      |                                 ~~^~~~~~~~~~~~
sugar.cpp:24:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |                         while (j < sugar.size() && sugar[j].first < ant[i].first - L) j++, remain = j < sugar.size() ? sugar[j].second : -1;
      |                                ~~^~~~~~~~~~~~~~
sugar.cpp:24:103: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |                         while (j < sugar.size() && sugar[j].first < ant[i].first - L) j++, remain = j < sugar.size() ? sugar[j].second : -1;
      |                                                                                                     ~~^~~~~~~~~~~~~~
sugar.cpp:25:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |                         while (j < sugar.size() && (sugar[j].first - ant[i].first) <= L && total_ants > 0) {
      |                                ~~^~~~~~~~~~~~~~
sugar.cpp:31:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |                                         remain = remain = j < sugar.size() ? sugar[j].second : -1;
      |                                                           ~~^~~~~~~~~~~~~~
sugar.cpp:31:48: warning: operation on 'remain' may be undefined [-Wsequence-point]
   31 |                                         remain = remain = j < sugar.size() ? sugar[j].second : -1;
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...