QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#700070 | #8936. Team Arrangement | rikka_lyly# | WA | 0ms | 3872kb | C++20 | 1.5kb | 2024-11-02 11:51:08 | 2024-11-02 11:51:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
void solve()
{
int n;
cin >> n;
vector<pair<int, int>> pr(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> pr[i].first >> pr[i].second;
}
sort(pr.begin() + 1, pr.end(), [&](const pair<int, int> &a, const pair<int, int> &b)
{
if(a.second != b.second)
return a.second < b.second;
return a.first < b.first; });
vector<int> w(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> w[i];
}
vector<ll> dp(n + 1, -INF);
dp[0] = 0;
for (int i = 1; i <= n; i++)
{
int nl = -INF, nr = INF, np = 0;
bool havesol = 0;
for (int j = i; j >= 1; j--)
{
np++;
nl = max(nl, pr[j].first);
nr = min(nr, pr[j].second);
if(np >= nl && np <= nr)
{
dp[i] = max(dp[i], dp[j - 1] + w[i - j + 1]);
havesol = 1;
}
}
// if(!havesol)
// {
// cout << "impossible\n";
// return;
// }
}
if(dp[n] == -INF)
cout << "impossible\n";
else
cout << dp[n] << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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: 3572kb
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: 3524kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
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: 3872kb
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'