Created
April 13, 2015 03:59
-
-
Save luccasiau/defdb36ecad62784d04f to your computer and use it in GitHub Desktop.
This file contains 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 <cstdio> | |
#include <algorithm> | |
#define MAXT 100005 | |
using namespace std; | |
int main(){ | |
int n; | |
scanf("%d",&n); | |
int A[MAXT]; | |
for(int i = 0;i<n;i++) scanf("%d",&A[i]); | |
int resp=0; | |
int B[MAXT]; | |
int tamb = 0; | |
B[0] = A[0]; | |
for(int i = 0;i<n;i++){ | |
tamb++; | |
for(int j = tamb;j>=1;j--){ | |
if(A[i] < B[j]){ | |
B[j+1] = B[j]; | |
resp++; | |
} | |
if(A[i] > B[j]){ | |
B[j+1] = A[i]; | |
break; | |
} | |
} | |
} | |
printf("%d\n",resp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá, uma dúvida,
na primeira iteração do laço que inicia na linha 18, quando j = 1 e i = 0, que valor B[j] assume (já que B[1] não foi inicializado até o momento) ?