题解:P11035 【MX-X3-T2】「RiOI-4」消えた夏の夢
众所周知加法有交换律,所以打乱操作顺序对结果没有影响,所以我们可以考虑对序列
对于一个数
一次操作:
两次操作:
所以,两次操作相当于不操作。所以,对于每个数,我们只需要确定是否需要操作即可。
题目要求
由于操作只进行一次,因此操作中
:::info[代码]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, p, x;
// 代码中的 x 相当于题目中的 a[i],p 相当于题目中的 x
void solve()
{
cin >> n >> p;
while (n--)
{
cin >> x;
if (x > 0) // 如果大于 0 就进行操作
{
p += x;
}
}
cout << p;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
:::