QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56833 | #4995. Highest Hill | wxw_sunming | WA | 30ms | 11940kb | C++ | 1.9kb | 2022-10-21 17:13:55 | 2022-10-21 17:14:39 |
Judging History
answer
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define inf 0x3f3f3f3f
#define endl '\n'
#define x first
#define y second
#define int long long
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
int a[N];
int w[N];
int id[N];
int cnt;
void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
if (a[1] <= a[2])
{
cnt++;
id[cnt] = 1;
w[cnt] = a[1];
}
for (int i = 2; i < n; i++)
{
if (a[i] < a[i - 1] && a[i] < a[i + 1])
{
cnt++;
id[cnt] = i;
w[i] = a[i];
}
}
if (a[n] <= a[n - 1])
{
cnt++;
id[cnt] = n;
w[n] = a[n];
}
int ans = 0;
for (int i = 2; i < n; i++)
{
if (a[i] >= a[i - 1] && a[i] >= a[i + 1])
{
int l = 1, r = cnt;
while (l < r)
{
int mid = l + r >> 1;
if (id[mid] >= i)
r = mid;
else
l = mid + 1;
}
int rr = id[l];
l = 1, r = cnt;
while (l < r)
{
int mid = (l + r + 1) >> 1;
if (id[mid] <= i)
l = mid;
else
r = mid - 1;
}
int ll = id[l];
if (a[i] >= w[ll] && a[i] >= w[rr])
{
int tot = fmin(a[i] - w[ll], a[i] - w[rr]);
ans = fmax(ans, tot);
}
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 7696kb
input:
11 0 1 2 3 4 5 4 3 2 1 0
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 3ms
memory: 7624kb
input:
10 29 85 88 12 52 37 19 86 7 44
output:
67
result:
ok single line: '67'
Test #3:
score: 0
Accepted
time: 2ms
memory: 7676kb
input:
3 2147483647 318000000000 2147483647
output:
315852516353
result:
ok single line: '315852516353'
Test #4:
score: 0
Accepted
time: 2ms
memory: 7696kb
input:
3 1 1 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 2ms
memory: 7764kb
input:
7 7 5 7 6 7 6 6
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 2ms
memory: 7840kb
input:
7 8 8 9 8 1 5 8
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 7560kb
input:
7 4 10 8 9 6 6 4
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 12ms
memory: 11776kb
input:
200000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 17ms
memory: 9668kb
input:
200000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 318000000000 3180000...
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 21ms
memory: 9816kb
input:
200000 159000000000 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 1590000...
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 15ms
memory: 9676kb
input:
199997 159000000000 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 159000000001 1590000...
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 12ms
memory: 11788kb
input:
200000 317999800001 317999800002 317999800003 317999800004 317999800005 317999800006 317999800007 317999800008 317999800009 317999800010 317999800011 317999800012 317999800013 317999800014 317999800015 317999800016 317999800017 317999800018 317999800019 317999800020 317999800021 317999800022 3179998...
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 17ms
memory: 9676kb
input:
200000 317999999999 317999999999 317999999998 317999999997 317999999996 317999999995 317999999994 317999999993 317999999992 317999999991 317999999990 317999999989 317999999988 317999999987 317999999986 317999999985 317999999984 317999999983 317999999982 317999999981 317999999980 317999999979 3179999...
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 27ms
memory: 11848kb
input:
200000 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 3179999...
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 24ms
memory: 11940kb
input:
200000 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 3179999...
output:
2
result:
ok single line: '2'
Test #16:
score: 0
Accepted
time: 26ms
memory: 11756kb
input:
200000 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 3179999...
output:
2
result:
ok single line: '2'
Test #17:
score: 0
Accepted
time: 26ms
memory: 9732kb
input:
200000 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999999 317999999998 317999999998 317999999998 317999999998 3179999...
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 30ms
memory: 9676kb
input:
200000 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 317999999998 3179999...
output:
2
result:
ok single line: '2'
Test #19:
score: -100
Wrong Answer
time: 24ms
memory: 11728kb
input:
200000 318000000000 318000000000 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 317999999999 3179999...
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'