Description
Input
Output
Data Constraint
做法:考虑贪心使得mina*minb最大,先以a为关键字排序,然后枚举删除最小的0~m个ai,对应删除最小的bi,然后更新答案。
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <queue> 5 #include <algorithm> 6 #define M 100007 7 #define LL long long 8 #define rep(i,a,b) for(int i=a;i<=b;i++) 9 using namespace std; 10 int T,n,m; 11 LL ans; 12 struct arr{ 13 int a,b,site; 14 }f[M]; 15 bool v[M]; 16 17 LL max(LL a,LL b) {return a>b?a:b;} 18 19 int Cmp(arr x,arr y){ 20 return x.a<y.a; 21 } 22 23 bool operator <(const arr &x,const arr &y){ 24 return x.b>y.b; 25 } 26 27 void Init(){ 28 memset(f,0,sizeof(f)); 29 scanf("%d%d",&n,&m); 30 rep(i,1,n) scanf("%d%d",&f[i].a,&f[i].b),f[i].site=i; 31 sort(1+f,f+n+1,Cmp); 32 } 33 34 void Work(){ 35 priority_queue<arr> q; 36 ans=0; 37 rep(i,m+1,n) q.push(f[i]); 38 arr now=q.top(); 39 ans=max(ans,(LL)f[m+1].a*now.b); 40 for(int i=m;i>=1;i--){ 41 q.pop(); 42 q.push(f[i]); 43 now=q.top(); 44 ans=max(ans,(LL)f[i].a*now.b); 45 } 46 now=q.top(); 47 ans=max(ans,(LL)f[1].a*now.b); 48 printf("%lld\n",ans); 49 } 50 51 int main() { 52 freopen("d.in","r",stdin); 53 freopen("d.out","w",stdout); 54 scanf("%d",&T); 55 for(;T--;){ 56 Init(); 57 Work(); 58 } 59 }