当前位置: 首页 > news >正文

Towers

题目描述

You are given n cubes in a certain order, and your task is to build towers using them. Whenever two cubes are one on top of the other, the upper cube must be smaller than the lower cube.
You must process the cubes in the given order. You can always either place the cube on top of an existing tower, or begin a new tower. What is the minimum possible number of towers?

输入

The first input line contains an integer n(1 ≤ n ≤ 2\times10^5): the number of cubes.
The next line contains n integers k1,k2,...,kn(1 ≤ ki ≤ $10^9$): the sizes of the cubes.

输出

Print one integer: the minimum number of towers.

样例输入
5
3 8 2 1 5
样例输出
2
代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans;
int main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);cin>>n;vector<ll>k(n);for(ll i=0;i<n;i++){cin>>k[i];}multiset<ll>s;for(ll i:k){if(s.empty()){ans++;s.insert(i);}else{auto it=s.upper_bound(i);if(it==s.end()){ans++;s.insert(i);}else{s.erase(it);s.insert(i);}}}cout<<ans;return 0;
}

http://www.lryc.cn/news/605871.html

相关文章:

  • AI+金融,如何跨越大模型和场景鸿沟?
  • NXP i.MX8MP GPU 与核心库全景解析
  • mac操作笔记
  • C++ 入门基础(2)
  • MySQL自动化安装工具-mysqldeploy
  • 关于AR地产发展现状的深度探究​
  • 【AI大模型】披着羊皮的狼--自动化生成越狱提示的系统(ReNeLLM)
  • 无人机传感器系统架构解析
  • 客户服务自动化:如何用CRM减少50%人工工单?
  • HOOPS Exchange技术架构全解析:打造高效CAD/BIM数据导入与导出引擎
  • AR智能巡检:制造业运维效率提升的关键
  • AR-Align-NN-2024
  • 11.结构体
  • 项目中如何定义项目范围
  • Python:如何从地球大数据科学服务中心批量下载VPM-GPP?
  • 《Java 程序设计》第 17 章 - 并发编程基础
  • Ceph、K8s、CSI、PVC、PV 深入详解
  • ros2 tf2详解
  • 从 0 到 1:PHP 基础到就业教程指南(附教程资料)
  • ceph sc 设置文件系统格式化参数
  • Python 程序设计讲义(48):组合数据类型——字典类型:字典的常用操作
  • 商旅平台怎么选?如何规避商旅流程中的违规风险?
  • 云原生技术创新中的安全和合规问题有哪些解决方案?
  • Java客户端连接Redis
  • 《计算机“十万个为什么”》之 [特殊字符] 字符集:数字世界的文字密码本 [特殊字符]️
  • OpenCV 中的「通道」(Channel)详解
  • Windows 安全中心是什么?如何关闭 Windows 11 的安全中心
  • centos下安装anaconda
  • Traccar:开源GPS追踪系统的核心价值与技术全景
  • VuePress 使用详解