垂死病中惊坐起 20分竟是我自己!!!

P2367 语文成绩

bronya666 @ 2024-10-21 21:30:33

#include<bits/stdc++.h>
const int N =5e6+5; 
using namespace std;
int student[N];
int student1[N];
int n,p;
int x,y,z;
int minn=101;
int main(){ 
    cin>>n>>p;
    for(int i=1;i<=n;i++){
        cin>>student[i];
    }
    for(int i=1;i<=n;i++){
        student1[i]=student[i]-student[i-1];
//      cout<<student1[i]<<" ";
    }
//  cout<<endl;
    while(p--){
        cin>>x>>y>>z;
        student[x]+=z,student[y+1]-=z;
    }
    for(int i=1;i<=n;i++){
//      cout<<student[i]<<" ";
        student1[i]=student1[i-1]+student[i];   
        minn=min(minn,student1[i]);
    }
    cout<<minn;
    return 0;
} 

by xywuyu @ 2024-10-21 21:34:20

#include <algorithm>
#include <iostream>
using namespace std;
int a[5000003];
int b[5000004];
int e,y;
int main() {
  int n, m,l,r;
  cin >> n>>m;

  for (int i = 1; i <= n; i++) {
    cin>>a[i];
b[i]=a[i]-a[i-1];
  }

for (int i = 1; i <= m; i++) {
      cin>>l>>r>>y;

b[l]+=y;b[r+1]-=y;
    }

for (int i=1;i<=n;i++)
{a[i]=a[i-1]+b[i];}
  sort (a+1,a+1+n);
cout<<a[1];
  return 0;
}

by Mzh2012 @ 2024-10-21 21:36:47

@bronya666

#include<bits/stdc++.h>
const int N =5e6+5; 
using namespace std;
long long student[N];
long long student1[N];
long long n,p;
long long x,y,z;
long long minn=1e10;
int main(){ 
    cin>>n>>p;
    for(long long i=1;i<=n;i++){
        cin>>student[i];
        student1[i]=student[i]-student[i-1];
        student[i] = student[i-1]+student1[i];
    }
//  cout<<endl;
    while(p--){
        cin>>x>>y>>z;
        student1[x]+=z,student1[y+1]-=z;
    }
    for(long long i=1;i<=n;i++){
//      cout<<student[i]<<" ";
        student[i]=student[i-1]+student1[i];    
        minn=min(minn,student[i]);
    }
    cout<<minn;
    return 0;
} 

所以为什么有些人要直接发自己的代码 xywuyu,不应该修改发帖的人的代码吗?


by 违规用户名Jx9)zIu @ 2024-10-21 21:37:01

@bronya666

#include<bits/stdc++.h>
using namespace std;
int l[5000005];
int a[5000005];
int main(){
    int n,p,min=INT_MAX;
    cin>>n>>p;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        l[i]=a[i]-a[i-1];
    }
    int x,y,z;
    for(int i=1;i<=p;i++){
        cin>>x>>y>>z;
        l[x]+=z;
        l[y+1]-=z;
    }
    for(int i=1;i<=n;i++){
        a[i]=a[i-1]+l[i];
        if(min>a[i]){
            min=a[i];
        }
    }
    cout<<min;
    return 0;
} 

求关


by bronya666 @ 2024-10-21 21:47:50

此贴结

悬关

感谢 @Mzh2012 dalao

希望有的人可以修改发帖的人的代码而不是直接发自己的代码


|