QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696237#8936. Team Arrangementlonelywolf#WA 0ms3656kbC++201.4kb2024-10-31 21:54:322024-10-31 21:54:33

Judging History

This is the latest submission verdict.

  • [2024-10-31 21:54:33]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3656kb
  • [2024-10-31 21:54:32]
  • Submitted

answer

#include <bits/stdc++.h>  
using namespace std;  

const int inf = 1e9;

signed main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

	int n;
	cin >> n;

	vector<pair<int, int>> t(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> t[i].first >> t[i].second;
	}

	sort(t.begin() + 1, t.end());

	vector<int> w(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
	}

	vector<int> a;
	a.reserve(100);

	int ans = -inf;
	int cnt = 0;
	auto dfs = [&](auto self, int sum) -> void {
		if (sum == 0) {
			cnt++;
			priority_queue<int, vector<int>, greater<>> pq;
			int j = 0;

			for (int k = a.size() - 1; k >= 0; k--) {
				int sz = a[k];
				while (j + 1 <= n && t[j + 1].first <= sz) {
					j++;
					pq.push(t[j].second);
				}
				while (sz--) {
					if (pq.empty() || pq.top() < sz) {
						return;
					}
					pq.pop();
				}
			}

			int val = 0;
			for (auto sz : a) {
				val += w[sz];
			}
			ans = max(ans, val);

			return;	
		}

		if (sum == n) {
			for (int i = 1; i <= n; i++) {
				a.push_back(i);
				self(self, sum - i);
				a.pop_back();
			}
			return;
		}
		int lst = a.back();
		for (int i = 1; i <= min(lst, sum); i++) {
			a.push_back(i);
			self(self, sum - i);
			a.pop_back();
		}
	};

	dfs(dfs, n);

	if (ans == -inf) {
		cout << "impossible\n";
	} else {
		cout << ans << "\n";
	}

    return 0;
}  
  

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3656kb

input:

3
2 3
1 2
2 2
4 5 100

output:

100

result:

wrong answer 1st lines differ - expected: '9', found: '100'