1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtCoder ABC 379 D - Home Garden

Last updated at Posted at 2024-11-09

コンテスト中に解けなかった問題を、自分的にわかりやすいコーディングで書き直したメモです。

(追記)投稿時に制約を勘違いしてました。これ、ACにはなってるけど、本当はTLEになるべきなんじゃないかなぁ‥‥

Main.cpp
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

int main( void )
{
	// 入力
	ll Q;
	cin >> Q;

	// プライオリティキューを 2 面用意しておく
	priority_queue<ll> queA;
	priority_queue<ll> queB;
	ll switchQue = 0;

	for( ll i = 0; i < Q; ++i)
	{
		int n;
		cin >> n;

		if( n == 1)
		{
			priority_queue<ll> & nowQue = (switchQue % 2)? queA : queB;
			nowQue.push(0);
		}
		else if( n == 2)
		{
			ll T;
			cin >> T;
			priority_queue<ll> & nowQue = (switchQue % 2)? queA : queB;
			priority_queue<ll> & altQue = (switchQue % 2)? queB : queA;

			while( ! nowQue.empty())
			{
				ll tmp = nowQue.top();
				altQue.push( tmp + T );
				nowQue.pop();
			}
			++switchQue;
		}
		else
		{
			ll H;
			cin >> H;
			priority_queue<ll> & nowQue = (switchQue % 2)? queA : queB;
			ll result = 0;
			while( ! nowQue.empty())
			{
				ll tmp = nowQue.top();
				if( tmp >= H)
				{
					nowQue.pop();
					++result;
				}
				else
				{
					break;
				}
			}
			cout << result << endl;
		}
	}

	return 0;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?