题目描述 Description

神犇YJQ有两个长度均为n的数列A和B,并且A是一个单调不增的数列。他认为这两个数列的优美度为。有一天YJQ很无聊,他把Bi进行重新排列,得到了许多不同的优美度。他想知道他能得到的最大的优美度和最小的优美度的差是多少。

输入描述 Input Description

第一行一个整数n表示数列长度,接下来n行每行两个整数表示Ai和Bi

输出描述 Output Description

一行,一个整数表示优美度的最大值与最小值的差

样例输入 Sample Input

2
2 1
1 2

样例输出 Sample Output

1

数据范围及提示 Data Size & Hint

对于30%的数据,n < 10;

对于50%的数据,n < 1000;

对于100%的数据,1 < n < 2 *10^5,1< Ai,Bi < 10^9。

请注意数据范围!!!!!!!!!!!!!!!!!!!

注意:10^5*10^9*10^9>18446744073709551615(Unsigned  Long Long的最大值)

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std; const int P=,L=,W=;
char s[L*W];
struct Big
{
int len;int data[L];bool fu;
void clear()
{
memset(data,,sizeof(data));
len=;fu=false;
}
int& operator [] (int k)
{
return data[k];
}
void operator = (int k)
{
clear();
if (k<) fu=true,k=-k;else fu=false;
len=;
while (k) data[++len]=k%P,k/=P;
if (len==) len=;
}
bool operator < (Big b)
{
bool t=false;
if (fu && !b.fu) return true;
if (!fu && b.fu) return false;
if (fu && b.fu) t=true;
if (len<b.len) return true^t;
if (len>b.len) return false^t;
for (int i=len;i;--i)
{
if (data[i]<b[i]) return true^t;
if (data[i]>b[i]) return false^t;
}
return false;
}
bool operator <= (Big b)
{
bool t=false;
if (fu && !b.fu) return true;
if (!fu && b.fu) return false;
if (fu && b.fu) t=true;
if (len<b.len) return true^t;
if (len>b.len) return false^t;
for (int i=len;i;--i)
{
if (data[i]<b[i]) return true^t;
if (data[i]>b[i]) return false^t;
}
return true;
}
bool operator > (Big b)
{
bool t=false;
if (fu && !b.fu) return false;
if (!fu && b.fu) return true;
if (fu && b.fu) t=true;
if (len<b.len) return false^t;
if (len>b.len) return true^t;
for (int i=len;i;--i)
{
if (data[i]<b[i]) return false^t;
if (data[i]>b[i]) return true^t;
}
return false;
}
bool operator >= (Big b)
{
bool t=false;
if (fu && !b.fu) return false;
if (!fu && b.fu) return true;
if (fu && b.fu) t=true;
if (len<b.len) return false^t;
if (len>b.len) return true^t;
for (int i=len;i;--i)
{
if (data[i]<b[i]) return false^t;
if (data[i]>b[i]) return true^t;
}
return true;
}
bool operator == (Big b)
{
if (fu!=b.fu) return false;
if (len<b.len) return false;
if (len>b.len) return false;
for (int i=len;i;--i)
if (data[i]!=b[i]) return false;
return true;
}
bool operator == (int k)
{
if (k<)
{
if (!fu) return false;
k=-k;
} else if (fu) return false;
if (k>=P)
{
Big b;b=k;
return *this==b;
}
else return len== && data[]==k;
}
bool operator != (Big b)
{
if (fu!=b.fu) return true;
if (len<b.len) return true;
if (len>b.len) return true;
for (int i=len;i;--i)
if (data[i]!=b[i]) return true;
return false;
}
bool operator != (int k)
{
if (k<)
{
if (!fu) return true;
k=-k;
} else if (fu) return true;
if (k>=P)
{
Big b;b=k;
return *this!=b;
}
else return !(len== && data[]==k);
}
Big operator + (Big b)
{
Big a=*this,c;c.clear();
if (a.fu && b.fu)
{
a.fu=false;b.fu=false;c=a+b;
if (c.len!= || c[]!=) c.fu=true;
return c;
}
if (a.fu && !b.fu)
{a.fu=false;return b-a;}
if (!a.fu && b.fu)
{b.fu=false;return a-b;}
a.len=max(a.len,b.len);
for (int i=;i<=a.len;++i)
{
a[i+]+=(a[i]+b[i])/P;
a[i]=(a[i]+b[i])%P;
}
if (a[a.len+]) ++a.len;
while (a[a.len]== && a.len>) --a.len;
return a;
}
Big operator + (int k)
{
Big a=*this,b;b=k;
return a+b;
}
Big operator - (Big b)
{
Big a=*this,c;c.clear();
if (a.fu && !b.fu)
{
a.fu=false;b.fu=false;c=a+b;
if (c.len!= || c[]!=) c.fu=true;
return c;
}
if (a.fu && b.fu)
{
a.fu=false;b.fu=false;return b-a;
}
if (!a.fu && b.fu)
{
b.fu=false; return a+b;
}
if (a<b) swap(a,b),a.fu=true;else a.fu=false;
for (int i=;i<=a.len;++i)
{
if (a[i]<b[i]) a[i]+=P,--a[i+];
a[i]-=b[i];
}
while (a[a.len]== && a.len>) --a.len;
if (a.len== && a[]==) a.fu=false;
return a;
}
Big operator - (int k)
{
Big a=*this,b;b=k;
return a-b;
}
Big operator * (Big b)
{
Big c;c.clear();
c.len=len+b.len-;
for (int i=;i<=len;++i)
for (int j=;j<=b.len;++j)
{
c[i+j-]+=data[i]*b[j];
c[i+j]+=c[i+j-]/P;
c[i+j-]%=P;
}
if (c[c.len+]) ++c.len;
while (c[c.len]== && c.len>) --c.len;
c.fu=fu^b.fu;
if (c.len== && c[]==) c.fu=false;
return c;
}
Big operator * (int k)
{
Big a=*this;
if (k<) a.fu=!a.fu,k=-k;
if (k>=P)
{
Big b;b=k;
return a*b;
}
for (int i=;i<=a.len;++i) a[i]*=k;
for (int i=;i<=a.len;++i)
a[i+]+=a[i]/P,a[i]%=P;
while (a[a.len+])
{
++a.len;
a[a.len+]=a[a.len]/P;
a[a.len]%=P;
}
while (a[a.len]== && a.len>) --a.len;
if (a.len== && a[]==) a.fu=false;
return a;
}
Big operator / (int k)
{
Big a=*this;int g=;
if (k<) a.fu=!a.fu,k=-k;
for (int i=a.len;i;--i)
{
a[i]+=g*P;
g=a[i]%k;
a[i]/=k;
}
while (a[a.len]== && a.len>) --a.len;
if (a.len== && a[]==) a.fu=false;
return a;
}
Big operator % (int k)
{
Big b;b=k;
return *this%b;
}
Big operator / (Big b)
{
Big c,d;c=;d=;c.fu=fu^b.fu;b.fu=false;
for (int i=len;i;--i)
{
d=d*P+data[i];
int ans=,l=,r=P-;
while (l<=r)
{
int mid=(l+r)>>;
if (b*mid<=d) ans=mid,l=mid+;
else r=mid-;
}
c[i]=ans;
d=d-b*c[i];
}
c.len=len;
while (c[c.len]== && c.len>) --c.len;
return c;
}
Big operator % (Big b)
{
Big c,d;c=;d=;c.fu=fu^b.fu;b.fu=false;
for (int i=len;i;--i)
{
d=d*P+data[i];
int ans=,l=,r=P-;
while (l<=r)
{
int mid=(l+r)>>;
if (b*mid<=d) ans=mid,l=mid+;
else r=mid-;
}
c[i]=ans;
d=d-b*c[i];
}
c.len=len;
while (c[c.len]== && c.len>) --c.len;
d=*this-b*c;
return d;
}
Big operator ^ (int t)
{
Big a=*this,ans;ans=;
while (t)
{
if (t&) ans=ans*a;t>>=;a=a*a;
}
return ans;
}
void read()
{
scanf("%s",s);
clear();
len=;
int pow=,t=,l=strlen(s),stop=;
if (s[]=='-') fu=true,stop=;
for (int i=l-;i>=stop;--i)
{
if (t>W) t=pow=,++len;
data[len]+=pow*(s[i]-'');
++t,pow*=;
}
}
void write()
{
if (fu) printf("%c",'-');
printf("%d",data[len]);
for (int i=len-;i;--i)
{
if (data[i]<) putchar('');
if (data[i]<) putchar('');
if (data[i]<) putchar('');
printf("%d",data[i]);
}
}
void writeln()
{
write();printf("\n");
}
} ;
inline long long read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
Big ansa,ansb,ansd,ansc;
long long a[],b[],n;
int main(){
cin>>n;
for(int i = ;i <= n;i++){
a[i] = read();
b[i] = read();
}
sort(b+,b++n);
for(int i = ;i <= n;i++){
ansd = a[i];
ansb = ansd *(b[n-i+] - b[i]);
ansc = ansc + ansb;
}
ansc.write();
return ;
}

codevs4437 YJQ Arranges Sequences的更多相关文章

  1. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  2. [Leetcode] Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  3. 论文阅读(Weilin Huang——【AAAI2016】Reading Scene Text in Deep Convolutional Sequences)

    Weilin Huang--[AAAI2016]Reading Scene Text in Deep Convolutional Sequences 目录 作者和相关链接 方法概括 创新点和贡献 方法 ...

  4. leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  5. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  6. Python数据类型之“序列概述与基本序列类型(Basic Sequences)”

    序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ...

  7. Extract Fasta Sequences Sub Sets by position

    cut -d " " -f 1 sequences.fa | tr -s "\n" "\t"| sed -s 's/>/\n/g' & ...

  8. 【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)

    4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 440  Solved: 16 ...

  9. MOOCULUS微积分-2: 数列与级数学习笔记 1. Sequences

    此课程(MOOCULUS-2 "Sequences and Series")由Ohio State University于2014年在Coursera平台讲授. PDF格式教材下载 ...

随机推荐

  1. css中border制作各种形状

    css利用border制作各种形状的原理如图: 使用border绘制三角形是什么原理?事实上,宽度相等的border是以45度对接的,如下图: 没有了上border如图所示: 再设置border的宽度 ...

  2. ES6学习笔记(1)----let和const命令

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ let和const命令 let 总结1.声明变量基本使用方法与var 相同  不同点  a.在代 ...

  3. Wamp搭建的服务器登录的时候出现Access denied for user 'hello'@'localhost' (using password: YES)

    想用自己电脑做一个服务器,然后就选择了Wamp,本来一切顺利,可是到登录的时候却出现了问题,出现了 Access denied for user 'hello'@'localhost' (using ...

  4. 使用 ArrayAdapter 来定制 ListView

    一个 ListView,其宽高都设为 match_parent,可以更省资源. activity_main.xml <ListView android:id="@+id/list_Vi ...

  5. iOS---iPad开发及iPad特有的特技

    iPad开发简单介绍 iPad开发最大的不同在于iPhone的就是屏幕控件的适配,以及横竖屏的旋转. Storyboard中得SizeClass的横竖屏配置,也不支持iPad开发. 1.在控制器中得到 ...

  6. 用16G内存在Java

    用16G内存在Java Map中处理30亿对象 在一个下雨的夜晚,我在思考Java中内存管理的问题,以及Java集合对内存使用的效率情况.我做了一个简单的实验,测试在16G内存条件下,Java的Map ...

  7. C++ 继承/派生、访问属性、构造函数

    1.子类继承父类的继承方式:public,private,protected,不写则默认为private: 2.子类会继承父类的全部成员(除了构造函数.析构函数,虽然析构函数有virtual,但是不是 ...

  8. C/C++ new/delete []、内存泄漏、动态数组

    一.概念 new/delete是用于动态分配和撤销内存的运算符.new/delete是c++里才有的,c中是用malloc和free,c++虽然也可以用,但是不建议用.当我们使用关键字new在堆上动态 ...

  9. (转)淘淘商城系列——引用dubbo服务

    http://blog.csdn.net/yerenyuan_pku/article/details/72758663 上文我们一起学习了如何发布一个dubbo服务,本文我就来教大家如何在web工程中 ...

  10. HTML5小時鐘

    <!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/T ...