E - Tozan and Gezan


Time limit : 2sec / Memory limit : 256MB

Score : 700 points

Problem Statement

You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is Ai, and the i-th element in B is Bi.

Tozan and Gezan repeats the following sequence of operations:

  • If A and B are equal sequences, terminate the process.
  • Otherwise, first Tozan chooses a positive element in A and decrease it by 1.
  • Then, Gezan chooses a positive element in B and decrease it by 1.
  • Then, give one candy to Takahashi, their pet.

Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.

Constraints

  • 1≤N≤2×105
  • 0≤Ai,Bi≤109(1≤iN)
  • The sums of the elements in A and B are equal.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A1 B1
:
AN BN

Output

Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.


Sample Input 1

Copy
2
1 2
3 2

Sample Output 1

Copy
2

When both Tozan and Gezan perform the operations optimally, the process will proceed as follows:

  • Tozan decreases A1 by 1.
  • Gezan decreases B1 by 1.
  • One candy is given to Takahashi.
  • Tozan decreases A2 by 1.
  • Gezan decreases B1 by 1.
  • One candy is given to Takahashi.
  • As A and B are equal, the process is terminated.

Sample Input 2

Copy
3
8 3
0 1
4 8

Sample Output 2

Copy
9

Sample Input 3

Copy
1
1 1

Sample Output 3

Copy
0

题意:求满足条件x*y<a*b最多的组数,其中a,b已知。
题解:要满足<a*b,x,y中必定存在<sqrt(a*b)的数;
① 如果t2*t2==a*b,在满足a==b的条件下,因为是<a*b,所以t2*2—2,因为a,b被计算了两次;否则在t2*t2==a*b的各种情况中还存在a!=t2&&a!=b的情况,所以还要-1;
② 如果满足t2*t2为最后一组满足条件的数时,只需要-1,(重复计算了t2*t2);
③ 否则的话-2(即在分别为a和b的条件时的两种情况; AC代码:
//#include    <bits/stdc++.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define N 500005
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
#define MOD 998244353
#define Mod 1e9 + 7
template<typename T> inline T max(T a,T b,T c){
return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
return min(a,min(b,c,d));
}
const int dx[]={,,,-,,,-,,-};
const int dy[]={,,,,-,,-,-,};
typedef long long ll;
using namespace std;
int main(){
ll n,a,b;
scanf("%lld",&n);
for (int i=;i<=n;i++){
scanf("%lld%lld",&a,&b);
ll t1=a*b;
ll t2=sqrt(t1);
if (t2*t2==t1){
if (a==b) printf("%lld\n",t2*-);
else printf("%lld\n",t2*-);
}
else if (t2*(t2+)<t1) printf("%lld\n",t2*-);
else printf("%lld\n",t2*-);
}
return ;
}

最新文章

  1. angular 源码分析 1 - angularInit()
  2. 理解 Cinder 架构 - 每天5分钟玩转 OpenStack(45)
  3. C#中时间的比较
  4. jQuery的$.ajax示例
  5. perl运行其他程序的5种方法
  6. Webform(简单控件、复合控件)
  7. JBuilder链接sql server数据库
  8. Android之ContextMenu的使用方法以及与OptionMenu的区别
  9. a便签 rel属性改变链接打开页面的方式
  10. qt info.plist 添加
  11. Mysql日期函数,时间函数使用的总结
  12. css阴影--box-shadow的用法
  13. codeforces 15D . Map 优先队列
  14. 14.6.3 Grouping DML Operations with Transactions 组DML操作
  15. HDOJ/HDU 2717 Catch That Cow 一维广度优先搜索 so easy..............
  16. 微信小程序中转义字符的处理
  17. Kubernetes(基础 一):进程
  18. 027_git添加多账号设置
  19. noip 2018游记
  20. HDU - 3564 Another LIS(LIS+线段树)

热门文章

  1. py02_01:初识模块
  2. java基础一(2020.1.3)
  3. goweb-文本处理
  4. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十一天】(购物车+订单)
  5. fatal: remote origin already exists.
  6. platform 平台驱动——设备的写作流程
  7. 微软不将《帝国时代》终极版上架Steam的原因到底是什么?
  8. Games
  9. XRichText
  10. C# 将多个DataTable添加到指定的DataSet中