当前位置:网站首页>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;
}
边栏推荐
- Unity shader (pass user data to shader)
- 有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
- Write VBA in Excel, connect to Oracle and query the contents in the database
- 【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
- Kubernetes cluster capacity expansion to add node nodes
- Unity shader (learn more about vertex fragment shaders)
- CodeForces - 1324D Pair of Topics(二分或双指针)
- Lesson 1: finding the minimum of a matrix
- Esp8266 uses TF card and reads and writes data (based on Arduino)
- JS inheritance prototype
猜你喜欢
Unity shader (learn more about vertex fragment shaders)
数据建模中利用3σ剔除异常值进行数据清洗
How to use clipboard JS library implements copy and cut function
Mysql:select ... for update
iNFTnews | 时尚品牌将以什么方式进入元宇宙?
How to speed up video playback in browser
How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
Dynamics 365Online ApplicationUser创建方式变更
Lesson 1: finding the minimum of a matrix
Flex flexible layout
随机推荐
The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
[bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
Lesson 1: hardness of eggs
如何成为一名高级数字 IC 设计工程师(5-3)理论篇:ULP 低功耗设计技术精讲(下)
How to solve the problem of golang select mechanism and timeout
农牧业未来发展蓝图--垂直农业+人造肉
Upload taro pictures to Base64
面试被问到了解哪些开发模型?看这一篇就够了
Netease Cloud Wechat applet
其实特简单,教你轻松实现酷炫的数据可视化大屏
进程间的通信方式
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
CodeForces - 1324D Pair of Topics(二分或双指针)
How to use clipboard JS library implements copy and cut function
【原创】程序员团队管理的核心是什么?
PostgreSQL reports an error when creating a trigger,
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
第十四次试验
shake数据库中怎么使用Mongo-shake实现MongoDB的双向同步啊?
Addition, deletion, modification and query of ThinkPHP database