QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602120#7744. ElevatorMiniLongTL 1ms5552kbC++174.7kb2024-09-30 19:53:482024-09-30 19:53:50

Judging History

你现在查看的是最新测评结果

  • [2024-09-30 19:53:50]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5552kb
  • [2024-09-30 19:53:48]
  • 提交

answer

#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
    #ifdef ONLINE_JUDGE
    char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
    #define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
    #else
    #define get() getchar()
    #endif
    template<typename T> inline void read(T &t){
        T x = 0, f = 1;
        char c = getchar();
        while(!isdigit(c)){
            if(c == '-') f = -f;
            c = getchar();
        }
        while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
        t = x * f;
    }
    template<typename T, typename ... Args> inline void read(T &t, Args&... args){
        read(t);
        read(args...);
    }
    template<typename T> void write(T t){
        if(t < 0) putchar('-'), t = -t;
        if(t >= 10) write(t / 10);
        putchar(t % 10 + '0');
    }
    template<typename T, typename ... Args> void write(T t, Args... args){
        write(t), putchar(' '), write(args...);
    }
    template<typename T> void writeln(T t){
        write(t);
        puts("");
    }
    template<typename T> void writes(T t){
        write(t), putchar(' ');
    }
    #undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
    const ll mod = 998244353;
    ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
    void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
    void add(ll &x, ll y){x = (x + y) % mod;}
    void mul(ll &x, ll y){x = x * y % mod;}
    ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
    ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
    ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e5 + 5;
ll n, k, cnt1, cnt2;
struct node{
    ll c, f;
    bool operator<(const node b)const{
        return f < b.f;
    }
}a[N], b[N];
int main(){
    multitest(){
        read(n, k);
        // if(tCase == 191) write(n, k), puts("");
        _rep(i, 1, n){
            ll c, w, f; read(c, w, f);
            if(w == 1) a[++cnt1] = {c, f};
            else b[++cnt2] = {c, f};
            // if(tCase == 191) write(c, w, f), puts("");
        }
        sort(a + 1, a + 1 + cnt1), sort(b + 1, b + 1 + cnt2);
        _rep(i, 1, cnt1) debug("(%d,%d) ", a[i].c, a[i].f); debug("\n");
        _rep(i, 1, cnt2) debug("(%d,%d) ", b[i].c, b[i].f); debug("\n");
        int l = cnt1, r = cnt2;
        ll ans = 0, cur = 0, maxn = 0;
        while(l || r){
        //     debug("(%d,%d) ans:%d cur:%d maxn:%d\n", l, r, ans, cur, maxn);
        // _rep(i, 1, l) debug("(%d,%d) ", a[i].c, a[i].f); debug("\n");
        // _rep(i, 1, r) debug("(%d,%d) ", b[i].c, b[i].f); debug("\n");
            while(l && !a[l].c) l--; while(r && !b[r].c) r--;
            if(!l && !r) break;
            if(r && (!l || b[r].f >= a[l].f)){
                if(b[r].c <= (k - cur) / 2) cur += 2 * b[r].c, maxn = max(maxn, b[r--].f);
                else{
                    if(!cur){
                        ans += b[r].c / (k / 2) * b[r].f;
                        b[r].c %= k / 2;
                    }else{
                        b[r].c -= (k - cur) / 2, cur += (k - cur) / 2 * 2, maxn = max(maxn, b[r].f);
                    }
                }
            }else{
                // debug("eee (%d,%d)\n", a[l].c, a[l].f);
                if(a[l].c <= k - cur) cur += a[l].c, maxn = max(maxn, a[l--].f);
                else{
                    if(!cur){
                        ans += a[l].c / k * a[l].f;
                        a[l].c %= k;
                    }else{
                        a[l].c -= k - cur, cur = k, maxn = max(maxn, a[l].f);
                    }
                }
            }
            debug("cur:%d\n", cur);
            if(cur == k - 1){
                while(l && !a[l].c) l--;
                if(l) cur++, a[l].c--, assert(a[l].f <= maxn);
            }
            if(cur == k) ans += maxn, cur = maxn = 0;
            debug("------------------\n");
        }
        if(cur) ans += maxn;
        // if(tCase <= 100)
        writeln(ans);
        cnt1 = cnt2 = 0;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5552kb

input:

2
4 6
1 1 8
7 2 5
1 1 7
3 2 6
8 1200000
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345

output:

24
100000

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

5501
8 104
5 2 3
6 2 4
5 2 3
6 2 9
8 2 4
2 1 3
7 2 4
8 2 8
1 290
3 1 1
12 12
6 1 2
1 2 2
1 1 2
1 2 4
6 1 1
1 2 5
6 1 4
4 1 4
6 2 4
6 2 5
4 2 5
4 1 4
5 334
1 1 4
1 2 3
4 2 1
5 1 1
2 1 2
13 218
5 2 3
5 1 4
1 2 1
1 2 5
3 2 2
1 1 3
4 2 2
1 2 5
2 2 1
2 1 5
3 2 1
5 2 1
1 1 4
10 260
7 2 1
5 1 1
5 2 4
6 1 6...

output:


result: