Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- //Pre: Llegeix seqüències d'n enters
- //Post: Escriu la màxima quantitat que es pot obtenir sumant des de cada costat
- int main() {
- int n, x;
- while (cin >> n) {
- vector<int> maxs(n);
- int maxed = 0; //Màxim esquerra-dreta
- int sumed = 0; //Suma esquerra-dreta
- int maxde = 0; //Màxim dreta-esquerra
- int sumde = 0; //Suma dreta-esquerra
- for (int i = 0; i < n; ++i) {
- cin >> x;
- maxs[i] = x;
- sumed = sumed + x;
- if (sumed > maxed) maxed = sumed;
- }
- for (int i = n-1; i >= 0; --i) {
- sumde = sumde + maxs[i];
- if (sumde > maxde) maxde = sumde;
- }
- cout << maxed << ' ' << maxde << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement