3645. 莫干山奇遇

Twisted9

奇怪的代码

include

using namespace std;
typedef long long ll;
vector A;
int main()
{
int n;
ll b,Max = 0;
cin >> n;
for(int i = 0;i < n;i++)
{
cin >> b;
A.push_back(b);
Max = max(b,Max);
}
ll p = Max + 1;
ll ans = 0;
ll a = 1;
ll x = A[0];

for(int i = 1;i < n;i++)
{
    if(A[i] > A[i-1])
    {
        a = A[i] + 1 - x;
    }
    else
    {
        a = p - x;
        ans += a;
        x = 0;
        a = A[i] + 1 - x;
    }
}
ans += a;
cout << ans << endl;

}

你当前正在回复 博客/题目
存在问题!