当前位置:网站首页>K gold Chef (two conditions, two points and difference)
K gold Chef (two conditions, two points and difference)
2022-06-26 14:23:00 【Honestbutter-】
link
Two points + Difference
Two point maximum ,check The solution satisfying two conditions is obtained .( What we used to do was to meet one condition , Pay attention to the difference )
Topic purpose : Make the common interval as long as possible , And the number of common intervals should be as many as possible .
We get two points each time mid, Refers to the number of people , Also refers to length .
And then the first one for The length of the circular record shall meet ≥mid Prefix and number of people , the second for The cyclic difference is consistent with ≥mid The length of the number , If the number of people sum[i]≥mid,return true,( Two conditions are met ).
#include<iostream>
#include<cstring>
using namespace std;
const int N=3e5+1000;
typedef pair<int,int> PII;
PII a[N];
int n,m,sum[N];
// Two point maximization feasible answer , For every time mid, Differential maintenance determines whether there is a continuous length not less than mid And the number of people is not less than mid The range of
bool check(int mid) // The number of ≥mid, length ≥mid
{
memset(sum,0,sizeof sum);
for(int i=0;i<m;i++)
{
int len=a[i].second-a[i].first+1;
if(len>=mid) // The first condition
{
sum[a[i].first+mid-1]++;
sum[a[i].second+1]--;
}
}
for(int i=1;i<=n;i++)
{
sum[i]+=sum[i-1];
if(sum[i]>=mid) // The second condition
return true;
}
return false;
}
int main()
{
cin>>n>>m;
for(int i=0;i<m;i++) cin>>a[i].first>>a[i].second;
int l=0,r=m-1;
while(l<r)
{
int mid=(l+r+1)/2;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
return 0;
}
边栏推荐
- Insect operator overloaded a fun
- array
- Obtain information about hard disk and volume or partition (capacity, ID, volume label name, etc.)
- Mathematical design D12 according to string function
- CVPR 2022文档图像分析与识别相关论文26篇汇集简介
- Sword finger offer 40.41 Sort (medium)
- C language | the difference between heap and stack
- C | analysis of malloc implementation
- [hnoi2010] flying sheep
- Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)
猜你喜欢
Correlation analysis related knowledge
Intellij IDEA--格式化SQL文件的方法
Relevant knowledge of information entropy
9 regulations and 6 prohibitions! The Ministry of education and the emergency management department jointly issued the nine provisions on fire safety management of off campus training institutions
Correlation of XOR / and
常用控件及自定义控件
BP neural network for prediction
Hard (magnetic) disk (I)
RISC-V 芯片架构新规范
Hands on data analysis unit 3 model building and evaluation
随机推荐
虫子 类和对象 中
First k large XOR value problem
9項規定6個嚴禁!教育部、應急管理部聯合印發《校外培訓機構消防安全管理九項規定》
Related knowledge of libsvm support vector machine
In insect classes and objects
ICML 2022 | LIMO: 一种快速生成靶向分子的新方法
Free machine learning dataset website (6300+ dataset)
Design of PHP asymmetric encryption algorithm (RSA) encryption mechanism
程序员必备,一款让你提高工作效率N倍的神器uTools
Leaflet loading ArcGIS for server map layers
7.consul service registration and discovery
C language ---getchar() and putchar()
(improved) bubble sorting and (improved) cocktail sorting
Heap optimization dijkstra/hash table storage node number
Is it safe to open a securities account? Is there any danger
AGCO AI frontier promotion (6.26)
虫子 类和对象 上
MySQL configuration improves data insertion efficiency
1075 pat judge (25 points)
Build your own PE manually from winpe of ADK