QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795691 | #6531. Base Station Construction | RUOHUI | WA | 0ms | 3636kb | C++20 | 1.0kb | 2024-11-30 23:17:53 | 2024-11-30 23:17:53 |
Judging History
answer
#include "bits/stdc++.h"
#define int long long
using namespace std;
int n, m;
void solve()
{
cin >> n;
vector<int> a(n + 2), R(n + 2);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
cin >> m;
for (int i = 1; i <= m; i++)
{
int l, r;
cin >> l >> r;
R[r] = max(R[r], l);
}
deque<int> q;
q.emplace_back(0);
vector<int> dp(n + 2);
for (int i = 1; i <= n + 1; i++)
{
dp[i] = dp[q.front()] + a[i];
while (q.size() && dp[q.back()] > dp[i])
{
q.pop_back();
}
q.emplace_back(i);
if (q.size() && q.front() < R[i])
{
q.pop_front();
}
}
cout << dp[n + 1] << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3636kb
input:
2 5 3 2 4 1 100 3 1 3 2 4 5 5 5 7 3 4 2 2 3 1 4 2 3 4 5
output:
3 4
result:
wrong answer 1st numbers differ - expected: '102', found: '3'