Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.002 s | 0 KBi |
#2 |
Correcto
|
0.001 s | 0 KBi |
#3 |
Correcto
|
0.002 s | 0 KBi |
#4 |
Correcto
|
0.012 s | 2 KBi |
#5 |
Correcto
|
0.005 s | 2 KBi |
#6 |
Correcto
|
0.001 s | 0 KBi |
#7 |
Correcto
|
0.002 s | 0 KBi |
#8 |
Correcto
|
0.001 s | 0 KBi |
#9 |
Correcto
|
0.001 s | 0 KBi |
#10 |
Correcto
|
0.005 s | 2 KBi |
#11 |
Correcto
|
0.002 s | 0 KBi |
#12 |
Correcto
|
0.003 s | 0 KBi |
#13 |
Correcto
|
0.001 s | 0 KBi |
#14 |
Correcto
|
0.006 s | 2 KBi |
#15 |
Correcto
|
0.007 s | 2 KBi |
#16 |
Correcto
|
0.003 s | 0 KBi |
#17 |
Incorrecto
|
0.05 s | 2 KBi |
#18 |
Incorrecto
|
0.047 s | 2 KBi |
#19 |
Incorrecto
|
0.049 s | 2 KBi |
#20 |
Incorrecto
|
0.048 s | 2 KBi |
#21 |
Incorrecto
|
0.114 s | 3 KBi |
#22 |
Incorrecto
|
0.05 s | 2 KBi |
#23 |
Correcto
|
0.044 s | 2 KBi |
#24 |
Correcto
|
0.049 s | 2 KBi |
#include <bits/stdc++.h> using namespace std; int maxSumSubArr(vector<int> a){ int n = a.size(); if(n <= 1) return a[0]; int m = n / 2; vector<int> l(a.begin(), a.begin()+m); vector<int> r(a.begin()+m, a.end()); int best = max(maxSumSubArr(l), maxSumSubArr(r)); int 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<int> a(n, 0); for(int i=0;i<n;i++) cin >> a[i]; cout << maxSumSubArr(a) << endl; return 0; }