徐淏宸1
(徐淏宸)
1
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
ll a[100005], l[100005], r[100005];
int main()
{
ll t;
cin >> t;
while(t--)
{
ll n, ans = 0;
cin >> n;
memset(l, 0, sizeof(l));
memset(r, 0, sizeof(r));
for(ll i = 1; i <= n; i++)
cin >> a[i];
for(ll i = 1; i <= n; i++)
l[i] = max(l[i - 1], a[i] + i);
l[0] = 0;
a[n + 1] = 0;
ans = 0;
for(ll i = n; i >= 1; i--)
r[i] = max(r[i + 1], a[i] - i);
for(ll i = 2; i < n; i++)
ans = max(a[i] + l[i - 1] + r[i + 1], ans);
cout << ans << endl;
}
return 0;
}
WA on #1
1 个赞
李欣悦
(李欣悦)
2
初始化是0
memset(r, 0, sizeof(r));
但是a[i]可能小于i,会有负数,比如样例1
r[i] = max(r[i + 1], a[i] - i);
解决:memset改成负数
1 个赞
周煊宸
(蒟蒻无了)
3
memset (r,-10e9,sizeof(r))
1 个赞
徐淏宸1
(徐淏宸)
7
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int a[100005], l[100005], r[100005];
int main()
{
int t;
cin >> t;
while(t--)
{
int n, ans = 0;
cin >> n;
memset(l, 0, sizeof(l));
memset(r, 255, sizeof(r));
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n; i++)
l[i] = max(l[i - 1], a[i] + i);
l[0] = 0;
a[n + 1] = 0;
ans = 0;
for(int i = n; i >= 1; i--)
r[i] = max(r[i + 1], a[i] - i);
for(int i = 2; i < n; i++)
ans = max(a[i] + l[i - 1] + r[i + 1], ans);
cout << '/' << ans << endl;
}
return 0;
}
这是我现在的代码
1 个赞
王天皓
(冰块萌兔)
8
for(int i = 1; i <= n; i++)
{
r[i] = -10e9;
}
1 个赞