蒟蒻求问
查看原帖
蒟蒻求问
867573
EEqualIPie楼主2024/10/22 07:43

为什么对to数组进行memset(to, 1, sizeof(to))会re,而在输入b[i]时顺便赋值却不会

#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5+10;
int n, a[N], b[N], to[N];
priority_queue<pii, vector<pii>, greater<pii> > pq;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    for(int i=1; i<=n; i++){
        to[i] = 1;
        scanf("%d", &b[i]);
        pq.push(make_pair(a[1]+b[i], i));
    }
    for(int i=1; i<=n; i++){
        printf("%d ", pq.top().first);
        int y = pq.top().second;
        pq.pop();
        pq.push(make_pair(a[++to[y]]+b[y], y));
    }
    return 0;
}
2024/10/22 07:43
加载中...