fuck the lakes
unknown
c_cpp
a year ago
2.3 kB
3
Indexable
Never
#include <bits/stdc++.h> using namespace std; // TO DO: re-write merging sums so they actualy merge into a single sum, and they have multiple areas for them going forward int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> sums; vector<pair<int, int>> area; // starting point, ending point bool streak = false; int sums_generated_in_line = 0, prev_sums_generated = 0; int best = 0; // filling the lines for (int y = 0; y < m; y++) { sums_generated_in_line = 0; for (int x = 0; x < n; x++) { int input; cin >> input; if (input != 0) { if (streak) { sums.back() += input; area.back().second = x; // update ending area point of the current area } else // new line lake area { sums_generated_in_line++; sums.push_back(input); area.push_back({x,x}); streak = true; } best = max(best, sums.back()); } else { streak = false; } } streak = false; // try meging the generated sums in the last two lines for (int i = sums.size() - sums_generated_in_line; i < sums.size(); i++) // loops through the last generated sums { for (int j = sums.size() - (sums_generated_in_line + prev_sums_generated); j < sums.size() - sums_generated_in_line; j++) // loop trough the before last generated sums { if (area[j].first <= area[i].second && area[i].first <= area[j].second) // we can merge the two sums { sums[i] += sums[j]; best = max(best, sums[i]); } } } prev_sums_generated = sums_generated_in_line; } cout << best << "\n"; } }