QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#556129 | #8936. Team Arrangement | ucup-team3519# | WA | 1ms | 3756kb | C++20 | 1.7kb | 2024-09-10 15:16:20 | 2024-09-10 15:16:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back
#define all1(x) (x).begin() + 1, (x).end();
#define all0(x) (x).begin(), (x).end();
typedef long long LL;
const LL INFLL = 1e18 + 10;
void solve() {
int n; cin >> n;
V<int> w(n + 1);
V<V<int>> hav(n + 1);
for(int i = 1; i <= n; i++) {
int l, r; cin >> l >> r;
hav[l].pb(r);
}
for(int i = 1; i <= n; i++) cin >> w[i];
LL ans = -INFLL;
V<int> team;
LL val = 0;
V<int> v;
auto dfs = [&](int x, int small, auto dfs) -> void {
if(x == 0) {
int now = 0;
bool ok = 1;
v.clear();
int l = 0;
for(auto x : team) {
while(now < x) {
now++;
for(auto y : hav[now]) {
v.push_back(y);
}
}
while(l != v.end() - v.begin() && v[l] < x) l++;
if(v.size() - l < x) {
ok = 0;
break;
}
l += x;
}
if(ok) {
ans = max(ans, val);
}
return;
}
for(int i = small; i <= x; i++) {
val += w[i];
team.pb(i);
dfs(x - i, i, dfs);
val -= w[i];
team.pop_back();
}
};
dfs(n, 1, dfs);
if(ans == -INFLL) cout << "impossible" << endl;
else cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
//cin >> t;
while(t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
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: 3756kb
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: 3620kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 2 3 1 2 2 2 -100 -200 100000
output:
-300
result:
ok single line: '-300'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3552kb
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:
6
result:
ok single line: '6'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3620kb
input:
14 3 3 1 2 2 3 2 3 2 3 1 1 2 3 1 3 3 3 1 3 1 3 1 2 2 3 1 3 -9807452 -9610069 4156341 2862447 6969109 -7245265 -2653530 -5655094 6467527 -6872459 3971784 7312155 9766298 -2719573
output:
-30127594
result:
wrong answer 1st lines differ - expected: '-16558567', found: '-30127594'