题目描述 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. 12 DOM操作应用

    1.创建子元素oLi=document.creatElement('li') 2.将元素附给父级元素oUl.appendChild(oLi) 3.将元素插入到父级元素里的第一位子元素之前oUl.ins ...

  2. 绿化VSCode

    通过啃源码, 终于找到了解决办法, 设置环境变量: VSCODE_APPDATA=C:\Program Files\VSCode\UserData VSCODE_EXTENSIONS=%VSCODE_ ...

  3. R in action读书笔记(22)第十六章 高级图形进阶(下)

    16.2.4 图形参数 在lattice图形中,lattice函数默认的图形参数包含在一个很大的列表对象中,你可通过trellis.par.get()函数来获取,并用trellis.par.set() ...

  4. 网页制作常用的CSS知识

    在制作网页中,我们会用到很多CSS的知识,在这里我简单的总结了一些. div    划分区块 ul,li 无序列表(配合划分区块) ol,li 有序列表 a 超链接标签 p 段落标签 h 标题标签 i ...

  5. 谈谈Java中的集合

    对于集合类,主要需要掌握的就是它的内部结构,以及遍历集合的迭代模式. 接口:Collection Collection是最基本的集合接口,一个Collection代表一组Object,即Collect ...

  6. (转)淘淘商城系列——SSM框架整合之Service层整合

    http://blog.csdn.net/yerenyuan_pku/article/details/72721108 上文我们一起学习了Dao层的整合,本文将教大家如何整合Service层. 我们需 ...

  7. bzero - 向字符串写入零

    总览 (SYNOPSIS) #include <string.h> void bzero(void *s, size_t n); 描述 (DESCRIPTION) bzero() 函数 把 ...

  8. dxf组码

    值 说明 -5 APP:永久反应器链 -4 APP:条件运算符(仅与 ssget 一起使用) -3 APP:扩展数据 (XDATA) 标记(固定) -2 APP:图元名参照(固定) -1 APP:图元 ...

  9. CAD交互绘制矩形框(com接口)

    主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY1 直线的开始点y坐标 DOUBLE ...

  10. 进程的互斥运行:CreateMutex函数实现只运行一个程序实例

    HANDLE hMutex=CreateMutex(NULL,TRUE,"HDZBUkeyDoctorTool"); if(hMutex) { if(ERROR_ALREADY_E ...