QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#540590 | #8936. Team Arrangement | ucup-team1264# | WA | 0ms | 3788kb | C++20 | 1.9kb | 2024-08-31 17:24:51 | 2024-08-31 17:24:52 |
Judging History
answer
// https://www.youtube.com/watch?v=R0P_f0gXXqs
// I could feel your heartbeat
// I could feel somewhere you’re looking down
// ‘Cause it’s you who I’m loving
// And it’s you that I want in need
#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define int i64
constexpr int INF = 1e18;
void solve() {
int n; cin >> n;
struct Seg {
int l, r;
bool operator<(const Seg& o) const {
return r < o.r;
}
};
vector<Seg> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].l >> a[i].r;
}
sort(a.begin(), a.end());
vector<int> w(n + 1);
for (int i = 1; i <= n; i++) {
cin >> w[i];
}
// partitions
vector<int> p;
int now_w = 0;
int ans = -INF;
function<void(int, int)> dfs = [&](int sum, int last) {
if (sum == n) {
vector<int> c = p;
int g = p.size(), l = 0;
for (int i = 0; i < n; i++) {
while (l < g && !c[l]) l++;
if (p[l] < a[i].l || p[l] > a[i].r) return;
else c[l]--;
}
ans = max(ans, now_w);
return;
}
for (int x = last; x + sum <= n; x++) {
if (x + sum != n && x + x + sum > n) continue;
now_w += w[x];
p.push_back(x);
dfs(sum + x, x);
now_w -= w[x];
p.pop_back();
}
};
dfs(0, 1);
if (ans == -INF) {
cout << "impossible\n";
} else cout << ans << "\n";
}
#undef int
// Make bold hypotheses and verify carefully
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
};
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3788kb
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: 3596kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
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: 3524kb
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'