题目描述 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. 174 Dungeon Game 地下城游戏

    一些恶魔抓住了公主(P)并将她关在了地下城的右下角.地下城是由 M x N 个房间组成的二维网格布局.我们英勇的骑士(K)最初被安置在左上角的房间里,并且必须通过地下城对抗来拯救公主.骑士具有以正整数 ...

  2. java课程设计全程实录——第3天

    参考资料: 课设主要指导: http://www.cnblogs.com/zhrb/p/6872265.html 2019年5月10日 https://blog.csdn.net/weixin_421 ...

  3. Mac 为啥不显示图片尺寸,点了显示简介也不显示~???

    这个问题困扰我好几天,然后今天想法子解决,我这个强迫症患者是真的难受,不能直接一目了然的,每次都要ps打开图片去看,真的好心累???? 网上98%的解决方法如下: 在 Finder 中,按快捷键 co ...

  4. Node.js——网站访问一般流程

  5. 前端Unicode转码的好处

    站长工具支持Unicode转码:http://tool.chinaz.com/Tools/Unicode.aspx (这是一个网页标题)转码后 ------>变为:\u8fd9\u662f\u4 ...

  6. vue2.0 组件化

    简单理解其实组件就是制作自定义的标签,这些标签在HTML中是没有的. 组件注册的是一个标签,而指令注册的是已有标签里的一个属性.在实际开发中我们还是用组件比较多,指令用的比较少. <!DOCTY ...

  7. Vue路由模式及监听

    当然详细情况还是看一下vue的官网吧 官网https://router.vuejs.org/zh/   hash模式下(默认) new VueRouter({ mode : ‘hash’, route ...

  8. windows sdk 设置窗体透明

    #define WINVER 0x0501 #include <windows.h> /* Declare Windows procedure */ LRESULT CALLBACK Wi ...

  9. C# 后台调用存储过程

    例一丶返回集合 [WebMethod] public object RegisterMethod(string type, string username, string password, stri ...

  10. vue开发 - 根据vue-router的meta动态设置html里标签的内容

    路由文件 :router/index.js import Vue from 'vue'import Router from 'vue-router'import index '@/view/index ...