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;
}
相关推荐
freexyn1 小时前
Matlab速成笔记七十:使用多项式函数进行曲线拟合
开发语言·笔记·matlab
alphaTao2 小时前
LeetCode 每日一题 2025/12/22-2025/12/28
算法·leetcode
tryxr2 小时前
Java抽象类特点、使用方式和应用场景
java·开发语言·向上转型·抽象类·向下转型
xiaolang_8616_wjl2 小时前
c++题目_传桶(改编于atcoder(题目:Heavy Buckets))
数据结构·c++·算法
kylezhao20192 小时前
C#上位机开发数据持久化:excel报表导入导出
开发语言·c#·excel
中國龍在廣州2 小时前
生成不遗忘,「超长时序」世界模型,北大EgoLCD长短时记忆加持
人工智能·深度学习·算法·自然语言处理·chatgpt
派大鑫wink2 小时前
Stream 流:简化集合操作的利器
java·开发语言
小小8程序员2 小时前
除了 gcc/g++,还有哪些常用的 C/C++ 编译器?
c语言·开发语言·c++
亓才孓2 小时前
java中的Math.Radom拓展
开发语言·python·算法