题目描述 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. 依赖注入(IOC) 详解

    https://blog.csdn.net/qq_27093465/article/details/52547290 https://blog.csdn.net/qq_27093465/article ...

  2. Java数组的交集、并集

    // 求两个数组的交集 public static int[] SameOfTwoArrays(int[] arr1, int[] arr2) { // 新建一个空数组,用于存储交集,空数组长度应该为 ...

  3. webpack 报错:Module build failed: Unknown word (1:1)

    解决方法:一是确保css配置里的"style-loader"必须在"css-loader"之前,二是将整个css配置注释掉,如下图:

  4. 掌握Spark机器学习库-01

    第1章 初识机器学习 在本章中将带领大家概要了解什么是机器学习.机器学习在当前有哪些典型应用.机器学习的核心思想.常用的框架有哪些,该如何进行选型等相关问题. 1-1 导学 1-2 机器学习概述 1- ...

  5. InChatter系统之本地化

    InChatter现在支持本地化了,其实这个只是很细节的东西,但是咱也是可以走走国际范.哈哈 其实最重要的原因只是想进行一次本地化的开发.这个概念相信大部分人都有,但是在实际项目中真的很少会涉及到,我 ...

  6. (二)Redis for 阿里云公网连接

    目录 (一)Redis for Windows正确打开方式 (二)Redis for 阿里云公网连接 (三)Redis for StackExchange.Redis 阿里云目前仅支持内网连接Redi ...

  7. F. Asya And Kittens并查集

    F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. ansible API(开发应用)

    7. ansible API(开发应用) 官网链接

  9. SQLServer锁的概述

    SQLServer锁的概述   锁的概述 一. 为什么要引入锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 丢失更新 A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了 ...

  10. find_in_set()和in()比较

    转载于:https://www.cnblogs.com/zqifa/p/mysql-4.html 作者:zqifa 因为自己太懒了,就从大佬那转载来,作为一次笔记! mysql 中find_in_se ...