답안 #704566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704566 2023-03-02T09:42:48 Z tonowak Ants and Sugar (JOI22_sugar) C++17
0 / 100
1 ms 212 KB
#include "bits/stdc++.h" // Tomasz Nowak
using namespace std;     // University of Warsaw
using LL = long long;
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
#define ssize(x) int(x.size())
template<class A, class B> auto& operator<<(ostream &o, pair<A, B> p) {
	return o << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &o, T x) -> decltype(x.end(), o) {
	o << '{'; int i = 0; for(auto e : x) o << (", ")+2*!i++ << e; return o << '}';
}
#ifdef DEBUG
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#else
#define debug(...) {}
#endif

LL get_ans(map<int, LL> ants, map<int, LL> sugars, int l) {
	LL ret = 0;
	while(not ants.empty() and not sugars.empty()) {
		auto [x, cnt] = *ants.begin();
		if(cnt == 0)
			ants.erase(ants.begin());
		else {
			auto [x_s, cnt_s] = *sugars.begin();
			if(cnt_s == 0 or x_s < x - l)
				sugars.erase(sugars.begin());
			else if(x > x_s + l)
				ants.erase(ants.begin());
			else {
				LL taking = min(cnt, cnt_s);
				ants.begin()->second -= taking;
				sugars.begin()->second -= taking;
				ret += taking;
			}
		}
	}
	return ret;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int q, l;
	cin >> q >> l;
	map<int, LL> ants, sugars;

	while(q --> 0) {
		int ti, xi, ai;
		cin >> ti >> xi >> ai;
		(ti == 1 ? ants : sugars)[xi] += ai;
		cout << get_ans(ants, sugars, l) << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -