题目描述 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. Android开发学习——简单类图

    1.类A继承于类B    (B 是父类,A是 子类) 2.小汽车.自行车 实现车的接口 3.A中有B这个成员变量,单向关联 4.聚合,整体与部分的关系.has-a  B中的构造函数(或set方法)需要 ...

  2. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第二天(非原创)

    文章大纲 一.课程介绍二.整合淘淘商城ssm项目三.Mybatis分页插件PageHelper使用四.整合测试五.项目源码与资料下载六.参考文章   一.课程介绍 一共14天课程(1)第一天:电商行业 ...

  3. 表单里的button默认是submit类型

    今天很坑爹,周六一大早加班开始码代码,本来想做数据加密测试,于是乎用tp框架搭建了一个应用环境,二话不说,开始码码. 但,今天一大早就栽坑!直到同事喊吃饭还在坑里出不来!吃完饭继续码,最后码的我想哭o ...

  4. Android 重定向 init.rc中服务的输出

    在init.rc中运行的服务,由于系统启动的时候将标准输出重定向到了/dev/null, 所以服务中的打印信息都不可见. 但调试时可能需要看到其中的打印信息,因此就有了logwrapper这个工具:l ...

  5. linux下mysql开启可访问

    修改mysql配置连接信息 将bind-address注释 vim /etc/my.cnf 修改mysql用户授权 mysql>GRANT ALL PRIVILEGES ON *.* TO ' ...

  6. h5混编问题总结

    h5混编总结: 1.fragment 格式错误导致跳转混乱的问题:修改格式: 2.有缓存回退js不执行问题:未解决: 3.无缓存跨域回退白屏问题:解决跨域问题. 4.

  7. 学生管理系统之Java+Mysql

    主页面: 代码如下:package appstu.view; import java.awt.BorderLayout;import java.awt.Dimension;import java.aw ...

  8. vue 发布build 本地设置 相对路径 两个地方 一个根目录用./ css文件里面用../../ 【也不好用,还是得手改】

    build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths a ...

  9. CAD参数绘制线型标注(网页版)

    主要用到函数说明: _DMxDrawX::DrawDimRotated 绘制一个线型标注.详细说明如下: 参数 说明 DOUBLE dExtLine1PointX 输入第一条界线的起始点X值 DOUB ...

  10. 入门迅速、应用广泛、月薪两万,马哥Python前景为什么这么好?

    随着Python的技术的流行,Python在为人们带来工作与生活上带来了很多的便捷,因为Python简单,学起来快,也是不少新手程序员入门的首选语言.新手们比较关心的就是Python的发展前景与方向. ...