#include<iostream> #include<queue> #include<list> #include<stdio.h> #include<vector> #include<map> #include<set> using namespace std; #define ull unsigned long long int #define FOR(i,n) for(int i=0;i<n;++i) #define FORD(i,n) for(int i=(n)-1;i>=0;--i) #define znakow 26 #define dcout 1 && cout int inline min(int a,int b){return a>b?b:a;} int inline max(int a,int b){return a<b?b:a;} int main(){ std::ios::sync_with_stdio(false); int n=0; cin>>n; ull*a=new ull[n]; ull*b=new ull[n]; multimap<ull,ull> f; FOR(i,n){ cin>>a[i]>>b[i]; f.insert(make_pair(a[i],b[i])); } int d=0; for(multimap<ull,ull>::iterator it=f.begin();it!=f.end();++it){ a[d]=it->first; b[d]=it->second; ++d; } int*h=new int[n]; FOR(i,n)h[i]=0; int chosen=0; ull sumA=0; ull sumDay=0; FOR(day,n){ int best=0; ull bestValue=0; ull leftSum=sumA; int chosenFromLeft=0; FOR(j,n){ if(h[j]){ leftSum-=a[j]; ++chosenFromLeft; continue; } ull newValue = b[j] + chosenFromLeft*a[j] + leftSum; if(newValue>=bestValue){ best=j; bestValue=newValue; } } h[best]=1; sumA+=a[best]; sumDay+=bestValue; cout<<sumDay<<endl; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include<iostream> #include<queue> #include<list> #include<stdio.h> #include<vector> #include<map> #include<set> using namespace std; #define ull unsigned long long int #define FOR(i,n) for(int i=0;i<n;++i) #define FORD(i,n) for(int i=(n)-1;i>=0;--i) #define znakow 26 #define dcout 1 && cout int inline min(int a,int b){return a>b?b:a;} int inline max(int a,int b){return a<b?b:a;} int main(){ std::ios::sync_with_stdio(false); int n=0; cin>>n; ull*a=new ull[n]; ull*b=new ull[n]; multimap<ull,ull> f; FOR(i,n){ cin>>a[i]>>b[i]; f.insert(make_pair(a[i],b[i])); } int d=0; for(multimap<ull,ull>::iterator it=f.begin();it!=f.end();++it){ a[d]=it->first; b[d]=it->second; ++d; } int*h=new int[n]; FOR(i,n)h[i]=0; int chosen=0; ull sumA=0; ull sumDay=0; FOR(day,n){ int best=0; ull bestValue=0; ull leftSum=sumA; int chosenFromLeft=0; FOR(j,n){ if(h[j]){ leftSum-=a[j]; ++chosenFromLeft; continue; } ull newValue = b[j] + chosenFromLeft*a[j] + leftSum; if(newValue>=bestValue){ best=j; bestValue=newValue; } } h[best]=1; sumA+=a[best]; sumDay+=bestValue; cout<<sumDay<<endl; } return 0; } |