1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> #include <algorithm> using namespace std; int n, m; int a[1005]; bool drop[1005]; inline int getMOD(int x) { return (x + n) % n; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; int sum = 0; int dropCnt = 0; for (int i = 0; i < n; i++) { cin >> m; int t; for (int j = 0; j < m; j++) { cin >> t; if (t > 0) { if (j != 0 && t < a[i]) drop[i] = true; a[i] = t; } else a[i] += t; } sum += a[i]; if (drop[i]) dropCnt++; } int group = 0; for (int i = 0; i < n; i++) { if (drop[getMOD(i - 1)] && drop[getMOD(i)] && drop[getMOD(i + 1)]) group++; } cout << sum << " " << dropCnt << " " << group; } |
CSP 201909-2 小明种苹果(续)
发表评论