QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#539645 | #8936. Team Arrangement | ucup-team3699# | WA | 0ms | 3708kb | C++14 | 1.6kb | 2024-08-31 15:19:34 | 2024-08-31 15:19:35 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 65;
int dp[N][N], w[N];
const int inf = 1e18 + 7;
pair<int, int> seg[N];
bitset<N> used;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> seg[i].second >> seg[i].first;
}
for(int i = 1; i <= n; i++){
cin >> w[i];
}
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
dp[i][j] = -inf;
}
}
dp[0][0] = 0;
sort(seg + 1, seg + 1 + n);
int ans = -inf;
for(int i = 1; i <= n; i++){
for(int j = i; j <= n; j++){
for(int k = 0; k <= i; k++){
if(dp[k][j - i] <= -1e9)
continue;
int cnt = 0;
used.reset();
for(int t = 1; t <= n && cnt < j - i; t++){
if(seg[t].second <= k){
used[t] = 1;
cnt++;
}
}
cnt = 0;
for(int t = 1; t <= n; t++){
if(!used[t] && seg[t].second <= i && seg[t].first >= i){
cnt++;
}
}
if(cnt >= i){
dp[i][j] = max(dp[i][j], dp[k][j - i] + w[i]);
}
}
}
ans = max(ans, dp[i][n]);
}
if(ans < -1e9){
cout << "impossible\n";
}else{
cout << ans << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3636kb
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: 3556kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3608kb
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: 3708kb
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: 3564kb
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:
7015295
result:
wrong answer 1st lines differ - expected: '-16558567', found: '7015295'