C++代码

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],t,d[10000];
int main(){
    cin>>n>>t;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i==1) d[i]=a[i];
		else d[i]=a[i]-a[i-1];
	}
	while(t--){
		int x,y,v;
		cin>>x>>y>>v;
		d[x]+=v;
		d[y+1]-=v;
	}
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+d[i];
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<" ";
	}
	return 0;
}
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],t,d[10000],ma=-1;
int main(){
    cin>>n>>t;
	while(t--){
		int v,f,to;
		cin>>v>>f>>to;
		d[f]+=v;
		d[to-1]-=v;
		ma=max(ma,to);
	}
	bool b=true;
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+d[i];
		if(a[i]>n) b=false;break;
	}
	if(b==true) cout<<"true";
	else cout<<"false";
	return 0;
}
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],t,d[10000],ma=-1;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		d[x]++;
		d[y-1]--;
	}
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+d[i];
		ma=max(ma,a[i]);
	}
	cout<<ma;
	return 0;
}
相关推荐
程与留9 小时前
15_国际化和本地化:tr()、ts 文件、QM 文件、多语言切换
c++·qt
地平线开发者10 小时前
【模型轻量化专题】衡量模型轻量性的指标
算法
程与留11 小时前
14_Qt 样式表(QSS)入门(语法、选择器、美化实战)
c++·qt
学习星球13 小时前
OFDM技术精讲:正交性推导、循环前缀原理与80行Python链路仿真(附实测数据)
算法·面试·前端框架
欧特克_Glodon19 小时前
OpenCV计算机视觉开发入门与实践<二十七>:图像分割概述
c++·人工智能·opencv·计算机视觉
蒸蒸yyyyzwd19 小时前
cpp 选手秋招学习笔记 day21
c++·面试·八股
alphaTao19 小时前
LeetCode 每日一题 2026/8/24-2026/8/30
python·算法·leetcode
Interview Aid11219 小时前
TikTok OA 四题分享|半小时内 AC,题目基本都是实现题
java·开发语言·算法·面试·职场和发展
CoderIsArt1 天前
C#中UI 线程与 Dispatcher
开发语言·ui·c#
顶点多余1 天前
那些在算法中适合巩固的知识点---1
java·前端·算法