QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#540638 | #8936. Team Arrangement | ucup-team3699# | RE | 0ms | 0kb | C++20 | 1.2kb | 2024-08-31 17:34:47 | 2024-08-31 17:34:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
const int mol=998244353;
vector<pair<int, int>>a;
priority_queue<int, vector<int>, greater<>>ha;
vector<int>rr[65];
int ans=-1e18, tot=0, n, w[65];
void dfs(int sum, int t){
if(sum==n){
ans=max(ans, tot);
return;
}
auto pre=ha;
for(int i=t;i<=n-sum;i++){
if(i!=n-sum&&n-sum-i<i) continue;
for(int j=t+1;j<=i;j++){
for(int ii: rr[j]) ha.push(ii);
}
if(ha.size()<i||ha.top()<i) {
ha=pre;
continue;
}
for(int j=1;j<=i;j++)
ha.pop();
tot+=w[i];
dfs(sum+i, i);
ha=pre;
tot-=w[i];
}
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
int l, r;
cin>>l>>r;
rr[l].pb(r);
}
for(int i=1;i<=n;i++) cin>>w[i];
dfs(0, 0);
if(ans==-1e18){
cout<<"impossible\n";
return;
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;
// cin>>t;
// while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 2 3 1 2 2 2 4 5 100