Cod sursa(job #2602681)
Utilizator | Data | 17 aprilie 2020 17:04:17 | |
---|---|---|---|
Problema | Shop | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.34 kb |
#import<fstream>
using namespace std;long long n,c,l,a[128],p[128],N,i,j,s,r,x,y,A[128];main(){ifstream q("shop.in");ofstream w("shop.out");q>>n>>c>>l;for(i=0;i<n;i++){q>>x>>y;a[x]=y;A[i]=x;}while(l){p[N]=l%c;l/=c;++N;}for(i=N-1;i>=0;i--){r=r*c+p[i];if(a[i]>=r)s+=r,a[i]=r,r=0;else r-=a[i],s+=a[i];}w<<s<<"\n";for(i=0;i<n;i++)w<<a[A[i]]<<" ";}