1 条题解

  • 0
    @ 2025-11-9 9:02:54
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    int a[10005];
    void solve() {
        int n; cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
        int ans = 1e18;
        // 每次统计在他后面比他大的
        // 再加上他前面的i-1个数即为当前i的成本,取最小值
        for(int i = 1; i <= n; i++){
            int cnt = 0;
            for(int j = i + 1; j <= n; j++)
            if(a[j] > a[i]){
                cnt++;
            }
            ans = min(ans, cnt + i - 1);
        }
        cout << ans << "\n";
    }
    signed main() {
        ios::sync_with_stdio(0);
        cin.tie(0),cout.tie(0);
        int T = 1;
        cin >> T;
        while (T--)
            solve();
        return 0;
    }
    
    • 1

    信息

    ID
    1182
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    (无)
    递交数
    40
    已通过
    20
    上传者