#include <bits/stdc++.h>
using namespace std;
int n, vacios=0;
struct vasos{
long long int tamanio;
int indice;
};
vasos Vasos[1005];
long long int acumulado=0;
long long int aux;
bool ordenar(vasos a, vasos b){
if(a.tamanio>b.tamanio) return true;
return false;
}
long long int listos[1005];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=0;i<n;i++){
cin>>aux;
acumulado+=aux;
cin>>Vasos[i].tamanio;
Vasos[i].indice=i;
}
sort(Vasos,Vasos+n,ordenar);
for(int i=0;i<n;i++){
if(acumulado==0) vacios++;
if(acumulado>=Vasos[i].tamanio){
listos[Vasos[i].indice]=Vasos[i].tamanio;
acumulado-=Vasos[i].tamanio;
}else{
listos[Vasos[i].indice]=acumulado;
acumulado=0;
}
}
cout<<vacios<<"\n";
for(int i=0;i<n;i++){
cout<<listos[i]<<" ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
416 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
380 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |