「CF529B」Group Photo 2(online mirror version)
题解
枚举高贪心
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 |
#include<cmath> #include<queue> #include<vector> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define pa pair<int,int> #define inf 1000000000 #define eps 1e-8 #define ll long long using namespace std; ll read() { ll 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,ans; int w[1005],h[1005]; bool vis[1005]; priority_queue<int,vector<int> >q; void solve(int x) { while(!q.empty())q.pop(); memset(vis,0,sizeof(vis)); int lie=0,sum=0; for(int i=1;i<=n;i++) if(h[i]>x) { vis[i]=1; lie++;sum+=h[i]; if(w[i]>x)return; } for(int i=1;i<=n;i++) if(!vis[i]) { if(w[i]<=x)q.push(w[i]-h[i]); sum+=w[i]; } while(lie<n/2&&!q.empty()) { int t=q.top();q.pop(); if(t>0)sum-=t,lie++; else break; } if(lie<=n/2)ans=min(ans,sum*x); } int main() { ans=2000000000; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&w[i],&h[i]); for(int i=0;i<=1000;i++) solve(i); printf("%d\n",ans); return 0; } |
Subscribe