Created
August 27, 2023 02:12
-
-
Save estelabn/3295a9ed03f71a66f351570d43b857cc 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 <bits/stdc++.h> //O(max(MAX_Pi, N)) | |
using namespace std; | |
const int MAX = 1e5 + 5; | |
//solução usando prefsum | |
int instante[MAX]; | |
int main(){ | |
int n; | |
cin >> n; | |
for(int i=0; i<n; i++){ | |
int c,p; | |
cin >> c >> p; // lendo a chegada e a partida | |
instante[c]++; // adicionando +1 para, na soma acumulada, repetir e indicar que há mais um ônibus | |
instante[p]--; // tirando -1 para, na soma acumulada, anular o +1 anterior e indicar que a permanência já acabou | |
} | |
int qntMaxOnibus = instante[0]; | |
for(int i = 1; i<MAX; i++){ | |
instante[i] = instante[i-1] + instante[i]; //fazendo a soma acumulada -> pode fazer instante[i] += instante[i-1]; | |
qntMaxOnibus = max(qntMaxOnibus, instante[i]); | |
} | |
cout << qntMaxOnibus*20 << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment