Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef struct{
- bool livre;
- int tempo;
- int cAtual;
- int tempoAcaba;
- }funcionario;
- int main (){
- int n, m;
- int *c;
- funcionario *v;
- int tempo = 0;
- int proxCliente = 0;
- int acabou;
- cin >> n;
- cin >> m;
- v = new funcionario[n];
- c = new int[m];
- for(int i=0; i<n; i++){
- cin >> v[i].tempo;
- v[i].livre = true;
- v[i].cAtual = 0;
- v[i].tempoAcaba = 0;
- }
- for(int i=0; i<m; i++){
- cin >> c[i];
- }
- while(true){
- acabou = 0;
- for(int i=0; i<n; i++){
- if(v[i].livre){
- acabou++;
- }else break;
- }
- if(acabou==n && proxCliente==m) break;
- tempo++;
- for(int i=0; i<n; i++){
- if(v[i].cAtual*v[i].tempo+v[i].tempoAcaba<=tempo){
- v[i].livre = true;
- v[i].tempoAcaba += v[i].cAtual*v[i].tempo;
- }
- }
- for(int i=0; i<n; i++){
- if(v[i].livre && proxCliente<m){
- v[i].livre = false;
- v[i].cAtual = c[proxCliente];
- proxCliente++;
- }
- }
- }
- cout << tempo << endl;
- delete[] v;
- delete[] c;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement