题解 | 植树节

植树节

https://www.nowcoder.com/practice/bf18f4e68f614b35a7a6c56c743d82fc

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
   int n;
   cin>>n;
   vector<int>tree(1e6,0);
   int max_s=-1;
   while(n--)
   {
        int a,b;
        cin>>a>>b;
        tree[a]+=1;
        tree[b+1]-=1;
        max_s=max(max_s,b);
   }
   for(int i=1;i<=max_s;i++)
        tree[i]+=tree[i-1];
    int max_t=*max_element(tree.begin(),tree.end());
    cout<<max_t;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

09-02 11:14
已编辑
四川大学 Java
吴offer选手:这种面试是最烦的,学不到东西,然后还被挂的莫名其妙。之前看到一种说法是面试官如果不想要你了,就会问一些很简单的问题,防止你举报他
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务