Last active
January 18, 2016 02:21
-
-
Save MagallanesFito/893cf4d6feb42bdc5587 to your computer and use it in GitHub Desktop.
Problema Preselectivo IOI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #define op_io ios_base::sync_with_stdio(0);cin.tie(0); | |
| using namespace std; | |
| typedef long long int LLI; | |
| struct Pila{ | |
| LLI altura; | |
| LLI posicion; | |
| }; | |
| Pila _Pila[1000002]; | |
| int edificios[1000002]; | |
| int tope = -1; | |
| LLI areaMax; | |
| int main(){ | |
| op_io | |
| LLI n; | |
| cin>>n; | |
| for(int i=0;i<n;i++) cin>>edificios[i]; | |
| tope++; | |
| edificios[n] = 0; | |
| _Pila[tope].altura = edificios[0]; | |
| _Pila[tope].posicion = 0; | |
| for(int i=1;i<=n;i++){ | |
| int altura = edificios[i]; | |
| if(altura >= _Pila[tope].altura){ | |
| tope++; | |
| _Pila[tope].altura = altura; | |
| _Pila[tope].posicion = i; | |
| } | |
| else{ | |
| while(_Pila[tope].altura >= altura && tope>=0){ | |
| LLI area = ((LLI)i - _Pila[tope].posicion)*_Pila[tope].altura; | |
| if(area > areaMax) areaMax = area; | |
| tope--; | |
| } | |
| tope++; | |
| _Pila[tope].altura = altura; | |
| } | |
| } | |
| cout << areaMax << "\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment