tongtong2012 @ 2024-05-29 20:12:36
80pts,#5TLE
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[9999999];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
int x,y,z;
while(m--){
cin>>x>>y>>z;
for(int i=x;i<=y;i++)a[i]+=z;
}
sort(a+1,a+1+n);
cout<<a[1];
return 0;
}
Why!
by tongtong2012 @ 2024-05-29 20:13:13
悬棺!
by HsNu1ly7_ @ 2024-05-29 20:14:29
用差分,建议去学习一下
#include <iostream>
using namespace std ;
int n , q , arr[5000010] , s[5000010] , c[5000010] ;
int main (){
cin >> n >> q ;
for ( int i = 1 ; i <= n ; i++ ){
cin >> arr[i] ;
}
for ( int i = 1 ; i <= q ; i++ ){
int x , y , z ;
cin >> x >> y >> z ;
s[x] += z ;
s[y + 1] -= z ;
}
int minn = 1233333 ;
for ( int i = 1 ; i <= n; i++ ){
c[i] = c[i - 1] + s[i] ;
minn = min ( minn , c[i] + arr[i] ) ;
}
cout << minn ;
return 0 ;
}
by tongtong2012 @ 2024-05-29 20:15:27
@HsNu1ly7_ 谢大佬!