当前位置:网站首页>Codeforces - 1324d pair of topics
Codeforces - 1324d pair of topics
2022-07-07 09:47:00 【moyangxian】
The question : A little
. :
Practice one : Two points
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N],b[N],c[N];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i],c[i]=a[i]-b[i];
sort(c+1,c+1+n);
ll ans=0;
for(int i=1;i<=n;i++){
if(c[i]<=0) continue;
int p=upper_bound(c+1,c+1+n,-c[i])-c;
ans+=i-p;
}
cout<<ans<<endl;
return 0;
}
Practice two : Double pointer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N],b[N],c[N];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i],c[i]=a[i]-b[i];
sort(c+1,c+1+n);
ll ans=0;
int l=1,r=n;
while(l<r){
if(c[l]+c[r]>0){
ans+=r-l;
r--;
}
else l++;
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- Network request process
- 12、 Sort
- PLC信号处理系列之开关量信号防抖FB
- VSCode+mingw64+cmake
- [bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
- Vs2013 generate solutions super slow solutions
- JS judge whether checkbox is selected in the project
- 【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
- 请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
- Communication mode between processes
猜你喜欢

使用BigDecimal的坑

flex弹性布局

Vs2013 generate solutions super slow solutions

Over 100000 words_ Ultra detailed SSM integration practice_ Manually implement permission management

面试被问到了解哪些开发模型?看这一篇就够了

VSCode+mingw64

VSCode+mingw64+cmake

小程序弹出半角遮罩层

Dynamics 365online applicationuser creation method change

First issue of JS reverse tutorial
随机推荐
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
农牧业未来发展蓝图--垂直农业+人造肉
第十四次试验
剑指 Offer II 107. 矩阵中的距离
Unity shader (to achieve a simple material effect with adjustable color attributes only)
Sqlplus garbled code problem, find the solution
【无标题】
Can flycdc use SqlClient to specify mysqlbinlog ID to execute tasks
如何使用clipboard.js库实现复制剪切功能
软件建模与分析
Redis common commands
Windows starts redis service
Information Security Experiment 4: implementation of IP packet monitoring program
shake数据库中怎么使用Mongo-shake实现MongoDB的双向同步啊?
洛谷P2482 [SDOI2010]猪国杀
sqlplus乱码问题,求解答
scrapy爬虫mysql,Django等
IIS faked death this morning, various troubleshooting, has been solved
HCIP 第一天 笔记整理
MySQL can connect locally through localhost or 127, but cannot connect through intranet IP (for example, Navicat connection reports an error of 1045 access denied for use...)