QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556095#8936. Team Arrangementucup-team3519#WA 0ms3848kbC++201.7kb2024-09-10 15:02:332024-09-10 15:02:33

Judging History

This is the latest submission verdict.

  • [2024-09-10 15:02:33]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3848kb
  • [2024-09-10 15:02:33]
  • Submitted

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;

    multiset<int> st;

    auto dfs = [&](int x, int small, auto dfs) -> void {
        if(x == 0) {
            int now = 0;
            bool ok = 1;
            for(auto x : team) {
                while(now < x) {
                    now++;
                    for(auto y : hav[now]) {
                        st.insert(y);
                    }
                }
                while(st.size() && *st.begin() < x) st.erase(st.begin());

                if(st.size() < x) {
                    ok = 0;
                    break;
                }
                for(int i = 1; i <= st.size(); i++) st.erase(st.begin());
            }
            if(ok) {
                ans = max(ans, val);
            }
        }
        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: 0ms
memory: 3848kb

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: 3468kb

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: 3536kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3544kb

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: 3784kb

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:

3

result:

wrong answer 1st lines differ - expected: '6', found: '3'