結果

問題 No.2453 Seat Allocation
ユーザー Challestend Rehtorbegnaro
提出日時 2023-09-01 21:49:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 2,191 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 55,248 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 01:43:55
合計ジャッジ時間 2,107 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <queue>
#define maxn 100000

namespace cltstream
{
	#define size 1048576
	char cltin[size + 1], *ih = cltin, *it = cltin;
	inline char gc()
	{
		#ifdef ONLINE_JUDGE
		if (ih == it)
		{
			it = (ih = cltin) + fread(cltin, 1, size, stdin);
			if (ih == it)
				return EOF;
		}
		return *ih++;
		#else
		return getchar();
		#endif
	}

	char cltout[size + 1], *oh = cltout, *ot = cltout + size;
	inline void pc(char c)
	{
		if (oh == ot)
		{
			fwrite(cltout, 1, size, stdout);
			oh = cltout;
		}
		*oh++ = c;
	}
	#define clop() fwrite(cltstream::cltout, 1, cltstream::oh - cltstream::cltout, stdout), cltstream::oh = cltstream::cltout
	#undef size

	template <typename _tp>
	inline void read(_tp& x)
	{
		char c = gc();
		for (; c != 45 && (c < 48 || c > 57) && c != EOF; c = gc());
		int sgn = c == 45 ? c = gc(), -1 : 1;
		for (x = 0; c >= 48 && c <= 57 && c != EOF; x = (x << 3) + (x << 1) + (c ^ 48), c = gc());
		x *= sgn;
	}

	template <typename _tp>
	inline void write(_tp x, char text = -1)
	{
		if (x < 0)
			pc(45), x = -x;
		if (!x)
			pc(48);
		else
		{
			int digit[22];
			for (digit[0] = 0; x; digit[++digit[0]] = x % 10, x /= 10);
			for (; digit[0]; pc(digit[digit[0]--] ^ 48));
		}
		if (text >= 0)
			pc(text);
	}

	inline void put(char str[], char text = -1)
	{
		for (int cur = 0; str[cur]; pc(str[cur++]));
		if (text >= 0)
			pc(text);
	}
}

int n, m;
int a[maxn + 5], b[maxn + 5];
struct node{ int x, y; };
std::priority_queue<node> heap;

inline bool operator<(const node &lhs, const node &rhs)
{
	long long L = 1LL * a[lhs.x] * b[rhs.y], R = 1LL * a[rhs.x] * b[lhs.y];
	if (L != R)
		return L < R;
	else
		return lhs.x > rhs.x;
}

int main()
{
	cltstream::read(n);
	cltstream::read(m);
	for (int i = 1; i <= n; ++i)
		cltstream::read(a[i]);
	for (int i = 1; i <= m; ++i)
		cltstream::read(b[i]);
	for (int i = 1; i <= n; ++i)
		heap.push({i, 1});
	for (int i = 1; i <= m; ++i)
	{
		node p = heap.top();
		heap.pop();
		if (p.y < m) heap.push({p.x, p.y + 1});
		cltstream::write(p.x, 10);
	}
	clop();
	return 0;
}
0