QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#821759 | #8936. Team Arrangement | HugeMouse | WA | 0ms | 3680kb | C++23 | 1.0kb | 2024-12-19 17:54:16 | 2024-12-19 17:54:17 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> group;
vector<pair<int, int>> a;
vector<int> w;
int ans;
bool check() {
vector<int> cnt = group;
int n = group.size(), m = a.size();
for (int i = 0, j = 0, k; i < n; ++i)
{
k = cnt[i];
while (k--)
{
auto &[l, r] = a[j];
if (l > cnt[i] || r < cnt[i]) return 0;
++j;
}
}
return 1;
}
void dfs(int cur, int step) {
if (cur == 0) {
if (!check()) return;
int sum = 0;
for (auto x : group) sum += w[x - 1];
ans = max(ans, sum);
return;
}
for (int i = step; i <= cur; i++) {
group.push_back(i);
dfs(cur - i, i);
group.pop_back();
}
}
int main() {
int n; cin >> n;
a.resize(n);
w.resize(n);
ans = -2e9;
for (auto &[l, r] : a) cin >> l >> r;
for (auto &x : w) cin >> x;
sort(a.begin(), a.end(), [](const auto &x, const auto &y) {
return x.second < y.second;
});
dfs(n, 1);
if (ans != -2e9) cout << ans << '\n';
else cout << "impossible\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
3 2 3 1 2 2 2 4 5 100
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
3 1 3 3 3 2 3 1 1 100
output:
100
result:
ok single line: '100'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
3 2 3 1 2 2 2 -100 -200 100000
output:
-300
result:
ok single line: '-300'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3680kb
input:
9 1 4 2 5 3 4 1 5 1 1 2 5 3 5 1 3 1 1 1 1 1 1 1 1 1 1 1
output:
5
result:
wrong answer 1st lines differ - expected: '6', found: '5'