当前位置:网站首页>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;
}
边栏推荐
- JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
- Unity shader (basic concept)
- Lecture 1: stack containing min function
- How to speed up video playback in browser
- CDZSC_2022寒假个人训练赛21级(1)
- PostgreSQL创建触发器的时候报错,
- golang select机制和超时问题怎么解决
- CMD startup software passes in parameters with spaces
- Windows starts redis service
- ComputeShader
猜你喜欢
Lesson 1: finding the minimum of a matrix
Oracle安装增强功能出错
Diffusion模型详解
Install pyqt5 and Matplotlib module
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
基于智慧城市与储住分离数字家居模式垃圾处理方法
Kubernetes cluster capacity expansion to add node nodes
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
Information Security Experiment 1: implementation of DES encryption algorithm
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
随机推荐
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
Information Security Experiment 2: using x-scanner scanning tool
flex弹性布局
Can flycdc use SqlClient to specify mysqlbinlog ID to execute tasks
2016 CCPC Hangzhou Onsite
洛谷P2482 [SDOI2010]猪国杀
**grafana安装**
沙龙预告|GameFi 领域的瓶颈和解决方案
数据建模中利用3σ剔除异常值进行数据清洗
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
Redis common commands
20排位赛3
Lesson 1: hardness of eggs
csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用
[bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
Netease Cloud Wechat applet
Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
CodeForces - 1324D Pair of Topics(二分或双指针)
Arthas simple instructions