大佬们,我这时间复杂度没错啊,为什么t了
查看原帖
大佬们,我这时间复杂度没错啊,为什么t了
1106289
KomorKomor楼主2024/8/17 17:20
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#define ll long long
#define pii pair<int, int> 
#define endl '\n'
#define inf 1e9
using namespace std;

void solve()
{   
    int n, c;   cin >> n >> c;
    ll id = 0, maxnn = -inf;
    ll a[200010] = {0}, sum[200010] = {0}, maxn[200010] = {0};
    for(int i = 1; i <= n; i++) cin >> a[i];
    a[1] += c;
    for(int i = 1; i <= n; i++)
    {
        if(a[i] > maxnn)
            maxnn = a[i], id = i;
    }
    for(int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
    for(int i = n; i >= 1; i--) maxn[i] = max(a[i], maxn[i + 1]);
    for(int i = 1; i <= n; i++)
    {
        if(a[i] == maxn[1] && id == i)   cout << 0 << ' ';
        else
        {
            int ans = i - 1;
            if(sum[i] < maxn[i + 1])    ans++;
            cout << ans << ' ';
        }
    }
    cout << endl;
}  

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t = 1;  cin >> t;
    while(t--)  solve();
    return 0;
}
2024/8/17 17:20
加载中...