标签:方法 code def codeforce ref int write ble pre
按边从小到大扫,先凑3个,没凑足的记录一下数量,后面大的优先跟这些凑,俩带走一个,多余的再凑3个,再……就这样走到最后即可。
const int maxn = 3e5 + 5;
int n;
ll ans, last;
int main() {
read(n);
rep(i, 1, n) {
int a;
read(a);
if (a >= last * 2) a -= last * 2, ans += last, last = 0;
else ans += a / 2, last -= a / 2, a %= 2;
ans += a / 3;
a %= 3;
last += a;
}
writeln(ans);
return 0;
}
标签:方法 code def codeforce ref int write ble pre
原文地址:https://www.cnblogs.com/AlphaWA/p/10664522.html