「CF493C」Vasya and Basketball
题解
从小到大枚举分界线的取值(只要枚举a或b中的值)
每次更新下小等于这个值的a,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 |
#include<map> #include<set> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000007 #define inf 2147483647 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 t1,t2; int l1,l2; int n,m,ans,ans1,ans2; int a[200005],b[200005],c[400005]; int main() { n=read(); for(int i=1;i<=n;i++)a[i]=read(),c[i]=a[i]; sort(a+1,a+n+1); m=read(); for(int i=1;i<=m;i++)b[i]=read(),c[i+n]=b[i]; sort(b+1,b+m+1); sort(c+1,c+n+m+1); ans1=n*3;ans2=m*3; ans=(ans1-ans2); l1=l2=0; for(int i=1;i<=n+m;i++) { while(l1!=n&&a[l1+1]<=c[i])l1++; while(l2!=m&&b[l2+1]<=c[i])l2++; t1=l1*2+(n-l1)*3,t2=l2*2+(m-l2)*3; if(t1-t2>ans||(t1-t2==ans&&t1>ans1))ans=t1-t2,ans1=t1,ans2=t2; } printf("%d:%d\n",ans1,ans2); return 0; } |
Subscribe