Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.001 s | 0 KBi |
#2 |
Correcto
|
0.003 s | 0 KBi |
#3 |
Correcto
|
0.001 s | 0 KBi |
#4 |
Correcto
|
0.009 s | 2 KBi |
#5 |
Correcto
|
0.002 s | 0 KBi |
#6 |
Correcto
|
0.002 s | 0 KBi |
#7 |
Correcto
|
0.002 s | 0 KBi |
#8 |
Correcto
|
0.002 s | 0 KBi |
#9 |
Correcto
|
0.002 s | 0 KBi |
#10 |
Correcto
|
0.002 s | 0 KBi |
#11 |
Correcto
|
0.003 s | 0 KBi |
#12 |
Correcto
|
0.007 s | 2 KBi |
#13 |
Correcto
|
0.002 s | 0 KBi |
#14 |
Correcto
|
0.004 s | 2 KBi |
#15 |
Correcto
|
0.002 s | 0 KBi |
#16 |
Correcto
|
0.002 s | 0 KBi |
#17 |
Correcto
|
0.054 s | 4 KBi |
#18 |
Correcto
|
0.057 s | 4 KBi |
#19 |
Correcto
|
0.048 s | 4 KBi |
#20 |
Correcto
|
0.051 s | 4 KBi |
#21 |
Correcto
|
0.049 s | 4 KBi |
#22 |
Correcto
|
0.045 s | 5 KBi |
#23 |
Correcto
|
0.047 s | 4 KBi |
#24 |
Correcto
|
0.048 s | 4 KBi |
#include <bits/stdc++.h> using namespace std; long long maxSumSubArr(vector<long long> a){ int n = a.size(); if(n <= 1) return a[0]; int m = n / 2; vector<long long> l(a.begin(), a.begin()+m); vector<long long> r(a.begin()+m, a.end()); long long best = max(maxSumSubArr(l), maxSumSubArr(r)); long long bsl, sl, bsr, sr; bsl = sl = a[m-1]; for(int i=m-2; i>=0; i--){ sl += a[i]; bsl = max(bsl, sl); } bsr = sr = a[m]; for(int i=m+1; i<n; i++){ sr += a[i]; bsr = max(bsr, sr); } return max(best, bsl+bsr); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // your code goes here int n; cin >> n; vector<long long> a(n); for(int i=0;i<n;i++) cin >> a[i]; cout << maxSumSubArr(a) << endl; return 0; }