为什么只得80分

P2367 语文成绩

zrx0204 @ 2024-10-20 15:58:50

~~~
#include<bits/stdc++.h>
using namespace std;  
int n, p, sum;
int a[100005];
bool cmp(int a, int s){
    return abs(a) < abs(s);
}
int main(){
    cin >> n >> p; 
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= p; i++){
        int x, y, z;
        cin >> x >> y >> z;
        for(int j = x; j <= y; j++) a[j] += z; 
    }
    sort(a + 1, a + 1 + n, cmp);
    cout << a[1];
    return 0;             
}

by snowball10185 @ 2024-11-01 22:12:01

@zrx0204

10^6×5×100>int范围

by snowball10185 @ 2024-11-01 22:13:15

好像没超


by snowball10185 @ 2024-11-01 22:17:21

@zrx0204

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

上一页 |