QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602098 | #7744. Elevator | MiniLong# | WA | 17ms | 7196kb | C++17 | 4.1kb | 2024-09-30 19:29:01 | 2024-09-30 19:29:01 |
Judging History
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);
_rep(i, 1, n){
ll c, w, f; read(c, w, f);
if(w == 1) a[++cnt1] = {c, f};
else b[++cnt2] = {c, f};
}
sort(a + 1, a + 1 + cnt1), sort(b + 1, b + 1 + cnt2);
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);
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, 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 && a[l].c >= k){
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);
}
}
}
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;
}
if(cur) ans += maxn;
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: 5708kb
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
Wrong Answer
time: 17ms
memory: 7196kb
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:
9 1 23 4 5 7 1 3 9 6 1 10 4 9 17 6 4 1 8 5 5 7 1 3 23 6 3 3 2 2 2 3 8 1 5 6 9 11 147 7 10 2 7 7 8 6 5 5 1 7 3 5 10 7 7 10 8 1 4 2 3 9 1 5 2 9 1 6 7 7 6 10 18 8 10 4 10 9 2 8 3 5 9 3 6 5 3 2 6 1 3 2 2 1 6 9 6 3 4 8 9 9 2 6 1 2 6 7 5 2 5 21 8 1 2 3 4 9 3 4 6 5 9 6 1 7 3 7 3 2 2 8 7 3 5 9 7 10 7 3 2 4 ...
result:
wrong answer 191st lines differ - expected: '21', found: '22'