Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.006 s | 2 KBi |
#2 |
Correcto
|
0.006 s | 1 KBi |
#3 |
Correcto
|
0.005 s | 1 KBi |
#4 |
Correcto
|
0.006 s | 1 KBi |
#5 |
Correcto
|
0.006 s | 1 KBi |
#6 |
Correcto
|
0.006 s | 2 KBi |
#7 |
Correcto
|
0.006 s | 1 KBi |
#8 |
Correcto
|
0.006 s | 5 KBi |
#9 |
Correcto
|
0.007 s | 13 KBi |
#10 |
Correcto
|
0.006 s | 2 KBi |
#11 |
Correcto
|
0.006 s | 1 KBi |
#12 |
Correcto
|
0.006 s | 5 KBi |
#13 |
Correcto
|
0.006 s | 1 KBi |
#14 |
Correcto
|
0.105 s | 5 KBi |
#15 |
Correcto
|
0.095 s | 5 KBi |
#16 |
Correcto
|
0.102 s | 5 KBi |
#17 |
Correcto
|
0.102 s | 5 KBi |
#18 |
Correcto
|
0.103 s | 5 KBi |
#19 |
Correcto
|
0.105 s | 5 KBi |
#20 |
Correcto
|
0.139 s | 5 KBi |
// https://codeo.app/problemas/0xf2-partir-un-arreglo-en-2 // Calculate index to which right part sum is negative and left side positive (bigger left) #include <iostream> #include <vector> using namespace std; int main() { int n, partitionIndex, rightSum; vector<int> arr, leftSumAt; // Read inputs cin >> n; arr = vector<int>(n); leftSumAt = vector<int>(n); int sumCache = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sumCache += arr[i]; leftSumAt[i] = sumCache; } partitionIndex = -1; rightSum = 0; // Navigate from right to left, checking left when right part sum is neg for (int i = n - 1; i > 0; i--) { rightSum += arr[i]; if (rightSum < 0 && leftSumAt[i - 1] > 0) { partitionIndex = i; } } // Output if (partitionIndex == -1) { cout << "Impossible" << endl; } else { cout << partitionIndex << endl; } return 0; }