当前位置:网站首页>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;
}
边栏推荐
- 章鱼未来之星获得25万美金奖励|章鱼加速器2022夏季创业营圆满落幕
- 沙龙预告|GameFi 领域的瓶颈和解决方案
- thinkphp3.2信息泄露
- PLC信号处理系列之开关量信号防抖FB
- **grafana安装**
- ComputeShader
- 请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
- In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
- Detailed explanation of diffusion model
- CDZSC_2022寒假个人训练赛21级(1)
猜你喜欢
nlohmann json
NATAPP内网穿透
Information Security Experiment 1: implementation of DES encryption algorithm
Dynamics 365Online ApplicationUser创建方式变更
VSCode+mingw64
基于智慧城市与储住分离数字家居模式垃圾处理方法
Dynamics 365online applicationuser creation method change
iNFTnews | 时尚品牌将以什么方式进入元宇宙?
Lesson 1: finding the minimum of a matrix
First issue of JS reverse tutorial
随机推荐
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
How to become a senior digital IC Design Engineer (5-3) theory: ULP low power design technology (Part 2)
第一讲:包含min函数的栈
Netease cloud wechat applet
VSCode+mingw64+cmake
Lesson 1: hardness of eggs
Dynamics 365online applicationuser creation method change
asp. How to call vb DLL function in net project
PostgreSQL reports an error when creating a trigger,
Niuke - Huawei question bank (61~70)
ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖
The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
**grafana安装**
scrapy爬虫mysql,Django等
洛谷P2482 [SDOI2010]猪国杀
H5 web player easyplayer How does JS realize live video real-time recording?
Final keyword
網易雲微信小程序
小程序实现页面多级来回切换支持滑动和点击操作
nlohmann json