题解 | #奖学金#正常大学生才能写出来的代码
奖学金
https://www.nowcoder.com/practice/cee98a512ec246a2918ea8121f7612c8
#include <iostream> using namespace std; int main() { long long r,avg,min_score,flag_a,flag_b,n; while(cin>>n>>r>>avg){ long long count=0,min_time=0; long long a[n],b[n]; for(long long i = 0; i < n; i++){ cin>>a[i]>>b[i]; count = count + a[i]; } for(long long i = 0; i < n; i++){ for(long long j = i+1; j < n; j++){ if(b[i]>b[j]){ flag_b=b[i]; b[i]=b[j]; b[j]=flag_b; flag_a=a[i]; a[i]=a[j]; a[j]=flag_a; } } } if(count/n-avg>=0) cout<<"0"<<endl; else{ min_score = avg*n-count; long long i=0; while(min_score>0){ if(min_score>=r-a[i]){ min_score=min_score-(r-a[i]); min_time=min_time+(r-a[i])*b[i]; }else{ min_time=min_time+min_score*b[i]; min_score=-1; } i++; } cout<<min_time<<endl; } } return 0; } // 64 位输出请用 printf("%lld")