P4447求调!!!

· · 个人记录

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#define ll long long
using namespace std;

struct G {
    ll l;
    ll len;
    bool operator>(const G& o) const {
        return len > o.len;
    }
};

int main(void) {
    cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    priority_queue<G, vector<G>, greater<G>> gs;
    for (ll x : a) {
        vector<G> temp;
        while (!gs.empty() && gs.top().l != x - 1) {
            temp.push_back(gs.top());
            gs.pop();
        }
        if (gs.empty()) {
            gs.push({x, 1});
        } else {
            G g = gs.top();
            gs.pop();
            g.l = x;
            g.len++;
            gs.push(g);
        }
        for (auto& g : temp) {
            gs.push(g);
        }
    }
    ll ans = INT_MAX;
    while (!gs.empty()) {
        ans = min(ans, gs.top().len);
        gs.pop();
    }
    cout << ans << endl;

    return 0;
}

一个点TLE,用很多方法去调没用THT。。。