题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书
题解:看到这题就想到了 poetize 的封印之门,然后就用差分序列水过了。。。不过把线段排序也可以一遍扫出来?
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 250000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
ll n,tot,a[maxn],b[maxn],c[maxn],d[maxn],s[maxn];
inline bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
n=read();
for1(i,n)a[i]=read(),a[n+i]=read();
for1(i,*n)c[i]=i;
sort(c+,c+*n+,cmp);
tot=;
for1(i,*n)
{
if(i==||a[c[i]]!=a[c[i-]])tot++;
b[c[i]]=tot;d[tot]=a[c[i]];
}
for1(i,n)
{
s[b[i]]++;s[b[n+i]+]--;
}
for1(i,tot)s[i]+=s[i-];
int ans=;
for1(i,tot)if(s[i]*d[i]>d[ans]*s[ans])ans=i;
printf("%lld\n",d[ans]*s[ans]);
return ;
}