暴力喜提最优解第二位(总时长101ms)
查看原帖
暴力喜提最优解第二位(总时长101ms)
1074084
asd890123楼主2024/7/12 12:22
#include <iostream>
#include <cctype>

#define debug(x) std::cout << #x << " = " << (x) << '\n'

inline __attribute((always_inline)) static void read(int &x){
    
    char c = getchar_unlocked();
    
    x = 0;
    while (!isdigit(c)) c = getchar_unlocked();
    while (isdigit(c)) x = x * 10 + c - '0',c = getchar_unlocked();
    
}

const int N = 1e5 + 5;

struct ticket{

    bool used;
    int time,price;

}a[N];

int main(){

    #ifndef ONLINE_JUDGE
        freopen("P5661.in","r",stdin);
        freopen("P5661.out","w",stdout);
    #endif

    std::cin.tie(0)->sync_with_stdio(0);

    int n,ans = 0,tot = 0;

    a[0].time = 0x3f3f3f3f;
    for (read(n);n--;){

        int op,price,t;

        read(op),read(price),read(t);
        if (op == 0){

            ans += price;
            a[++tot] = (ticket){false,t,price};
            
        }
        else{

            int pos = 0;

            for (int i = tot;i;i--){

                if (price <= a[i].price && t - a[i].time <= 45 && !a[i].used && a[i].time < a[pos].time) pos = i;
                if (t - a[i].time > 45) break;

            }
            if (pos) a[pos].used = true;
            else ans += price;

        }

    }
    std::cout << ans << '\n';

    return 0;
}

最优解前几页都开快读的。

意思:本题与队列啥关系

2024/7/12 12:22
加载中...