Submission #571988

#TimeUsernameProblemLanguageResultExecution timeMemory
5719888e7Ants and Sugar (JOI22_sugar)C++17
6 / 100
4070 ms1536 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ...b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 100005 #define pii pair<ll, ll> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); int main() { io int q, l; cin >> q >> l; vector<pii> v1, v2, t2; while (q--) { { int t, x; ll v; cin >> t >> x >> v; if (t == 1) { v1.push_back({x, v}); } else { t2.push_back({x, v}); } } v2 = t2; sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); int ind = 0; ll ans = 0; for (int i = 0;i < v1.size();i++) { ll tmp = v1[i].ss; while (ind < v2.size()) { if (v2[ind].ff < v1[i].ff - l) ind++; else if (v2[ind].ff > v1[i].ff + l) { break; } else if (v2[ind].ss < tmp) { ans += v2[ind].ss; tmp -= v2[ind].ss; ind++; } else { ans += tmp; v2[ind].ss -= tmp; break; } } } cout << ans << "\n"; } }

Compilation message (stderr)

sugar.cpp: In function 'int main()':
sugar.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int i = 0;i < v1.size();i++) {
      |                  ~~^~~~~~~~~~~
sugar.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    while (ind < v2.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...