Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int countStableSubsegmentsBrute(const vector<int>& capacity) {
- int n = capacity.size();
- int count = 0;
- for (int l = 0; l < n; ++l) {
- long long midSum = 0;
- for (int r = l + 1; r < n; ++r) {
- if (r - l >= 2) { // length ≥ 3
- midSum += capacity[r - 1];
- if (capacity[l] + capacity[r] == midSum) {
- count++;
- }
- } else {
- midSum += capacity[r - 1];
- }
- }
- }
- return count;
- }
- int main() {
- vector<int> capacity = {9, 3, 3, 3, 9};
- cout << "Stable subsegments: " << countStableSubsegmentsBrute(capacity) << endl; // Output: 2
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment