Skip to content

Instantly share code, notes, and snippets.

@luccasiau
Created April 13, 2015 03:59
Show Gist options
  • Save luccasiau/defdb36ecad62784d04f to your computer and use it in GitHub Desktop.
Save luccasiau/defdb36ecad62784d04f to your computer and use it in GitHub Desktop.
#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;
}
@LukeC8
Copy link

LukeC8 commented Oct 2, 2015

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) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment