QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619297 | #8936. Team Arrangement | ucup-team4074# | WA | 0ms | 3828kb | C++20 | 1.8kb | 2024-10-07 13:48:22 | 2024-10-07 13:48:23 |
Judging History
answer
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define pb push_back
using namespace std;
const int N = 65;
void solve();
signed main() {
// fast
int t = 1;
// cin >> t;
while (t--) solve();
}
int ans(-1e9);
int n, w[N];
struct item {
int l, r;
} a[N];
bool cmp(item x, item y) {
return x.l <= y.l;
}
template<typename T>
class CMP {
public:
bool operator()(T x, T y) {
return a[x].r < a[y].r;
}
};
priority_queue<int, vector<int>, CMP<int>> q;
vector<int> now;
int now_val;
int check() {
// cout << 1 << '\n';
int flag(1), head(1);
while (!q.empty())q.pop();
for (int i = 1; i <= n; i++) {
while (a[head].l <= now[i] && head <= n)q.push(head), head++;
if ((!q.empty()) && a[q.top()].r < now[i - 1]) {
flag = 0;
}
if (!q.empty())q.pop();
else flag=0;
}
if (!q.empty() || head <= n)flag = 0;
return flag;
}
void dfs(int sum, int lim) {
if (sum == 0) {
if (check()) {
ans = max(ans, now_val);
}
return;
}
for (int i = lim; i <= sum; i++) {
now_val += w[i];
for (int j = 1; j <= i; j++)
now.push_back(i);
dfs(sum - i, i);
for (int j = 1; j <= i; j++)now.pop_back();
now_val -= w[i];
}
return;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i].l >> a[i].r;
for (int i = 1; i <= n; i++)cin >> w[i];
stable_sort(a + 1, a + n + 1, cmp);
dfs(n, 1);
if (ans == -1000000000)cout << "impossible";
else cout << ans << '\n';
return;
}
/*
3
2 3
1 2
2 2
4 5 100
3
1 3
3 3
2 3
1 1 100
2
1 1
2 2
1 1
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
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: 3780kb
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: 3488kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3796kb
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: 3828kb
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:
7
result:
wrong answer 1st lines differ - expected: '6', found: '7'