QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#628350 | #8936. Team Arrangement | ucup-team1266# | WA | 0ms | 3704kb | C++20 | 1.3kb | 2024-10-10 19:47:31 | 2024-10-10 19:47:33 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using ull = unsigned long long;
#define pii array<ll,2>
#define endl '\n'
using namespace std;
const int N=4e5+5;
int k;
int a[65],tmp[65];
array<int,2>man[65]; //man[i][0]是r [i][1]是l
ll w[65];
int n;
bool check(int len){
int j=len-1,tmp=0; //从第一组开始分配
for(int i=1;i<=n;i++){
if(man[i][1]>a[j]) return false;
if(man[i][0]<a[j]) return false;
tmp++;
if(tmp==a[j]){
j--;
tmp=0;
}
}
return true;
}
ll dfs(int rem,int lst,int len){
ll res=-1e9;
if(rem==0){
if(!check(len)) return -1e9;
res=0;
for(int i=1;i<len;i++) res+=w[a[i]];
return res;
}
for(int i=1;i<=lst&&rem-i>=0;i++){
a[len]=i;
res=max(res,dfs(rem-i,i,len+1));
a[len]=0;
}
return res;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>man[i][1]>>man[i][0];
sort(man+1,man+n+1);
for(int i=1;i<=n;i++) cin>>w[i];
ll res=dfs(n,n,1);
if(res==-1e9){
cout<<"impossible";
return;
}
cout<<res;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// int T=1;cin>>T;while(T--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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: 3656kb
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: 3584kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3704kb
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: 3644kb
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'