QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795669 | #6531. Base Station Construction | RUOHUI | WA | 45ms | 10604kb | C++20 | 1.1kb | 2024-11-30 22:57:27 | 2024-11-30 22:57:28 |
Judging History
answer
#include "bits/stdc++.h"
#define int long long
using namespace std;
const int N = 2e6 + 10;
int n, m, k;
int a[N], b[N], dp[N], f[N], num, ans;
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
b[i] = 0;
}
cin >> m;
int re=0;
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
b[y] = max(b[y], x);
re=max(re,y);
}
int h = 1, d = 1;
f[1] = 0;
for (int i = 1; i <= n; i++)
{
dp[i] = dp[f[h]] + a[i];
while (h <= d && dp[f[d]] > dp[i])
d--;
f[++d] = i;
//cout << i << " " << f[h] << " " << dp[i] << " " << b[i] << "\n";
while (h <= d && f[h] < b[i])
h++;
//cout<<dp[i]<<" ";
}
int ans=dp[re];
for(int i=b[n];i<=re;i++)
{
ans=min(dp[i],ans);
//cout<<dp[i]<<" ";
}
cout << ans << "\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7748kb
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:
102 5
result:
ok 2 number(s): "102 5"
Test #2:
score: -100
Wrong Answer
time: 45ms
memory: 10604kb
input:
6201 12 88 78 46 95 84 98 55 3 68 42 6 18 19 6 9 10 11 12 12 8 11 8 12 2 3 2 3 1 5 9 9 7 8 6 11 2 4 12 12 2 4 2 9 7 10 8 8 1 7 6 11 5 76 27 48 66 61 2 1 4 3 5 8 64 81 20 6 86 9 4 55 1 7 7 9 1 43 18 81 11 22 9 61 83 14 5 6 2 6 5 8 1 4 9 9 9 9 7 7 2 5 8 9 5 6 4 8 5 8 9 9 6 6 10 66 41 84 7 80 31 22 96 ...
output:
141 48 0 126 303 141 0 170 159 139 153 194 136 89 230 93 287 89 124 130 148 0 0 193 36 0 239 303 236 150 177 57 0 0 24 0 83 160 108 62 35 122 156 81 115 138 54 242 126 28 94 86 311 244 262 87 302 0 86 16 30 129 75 91 90 179 81 224 142 154 0 111 194 247 0 0 66 0 213 101 258 137 177 0 204 153 146 130 ...
result:
wrong answer 3rd numbers differ - expected: '4', found: '0'