「CF492C」Vanya and Exams
题解
贪心选取b最小的。。
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 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<map> #include<ctime> #include<vector> #include<set> #include<cmath> #include<algorithm> #define inf 1000000000 #define ll long long #define pa pair<int,int> using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,r; ll avg,sum,lim,ans; struct data{int a,b;ll lim;}a[100005]; bool operator<(data a,data b) { return a.b<b.b; } int main() { n=read();r=read();avg=read(); avg*=n; for(int i=1;i<=n;i++) { a[i].a=read(),a[i].b=read(),sum+=a[i].a; a[i].lim=(r-a[i].a); } if(sum>=avg){puts("0");return 0;} sort(a+1,a+n+1); for(int i=1;i<=n&&sum<avg;i++) { ll t=min(avg-sum,a[i].lim); sum+=t; ans+=t*a[i].b; } printf("%I64d",ans); return 0; } |
ORZ,求个联系方式,求深交。。
留言板有