結果

問題 No.393 2本の竹
ユーザー snrnsidy
提出日時 2021-07-04 01:42:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 3,583 ms
コンパイル使用メモリ 196,664 KB
最終ジャッジ日時 2025-01-22 17:24:15
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int tc;

	cin >> tc;

	while (tc--)
	{
		int n1, n2;
		int m;
		int res = 0;
		vector <int> v;

		cin >> n1 >> n2;
		cin >> m;
		for (int i = 0; i < m; i++)
		{
			int t;
			cin >> t;
			v.push_back(t);
		}
		sort(v.begin(), v.end());
		int sum1 = 0;
		int sum2 = 0;
		if (n1 < n2)
		{
			int temp = n1;
			n1 = n2;
			n2 = temp;
		}
		for (int i = 0; i < m; i++)
		{
			if (sum2 + v[i] > n2)
			{
				if (sum1 + v[i] <= n1)
				{
					res++;
					sum1 += v[i];
				}
			}
			else
			{
				if (i % 2 == 0)
				{
					sum1 += v[i];
				}
				else
				{
					sum2 += v[i];
				}
				res++;
			}
		}
		cout << res << '\n';
	}
	return 0;
}
0