QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466066 | #7744. Elevator | evirir# | WA | 102ms | 5432kb | C++14 | 2.6kb | 2024-07-07 15:28:17 | 2024-07-07 15:28:17 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 1e5+5;
ll f[3][MAXN];
int main()
{
int t;
cin>>t;
while(t--){
ll n,k;
cin>>n>>k;
k/=2;
vector<int>crd;
for(int i=0;i<n;i++){
int c,w,f0;
cin>>c>>w>>f0;
f[w][f0]+=c;
crd.pb(f0);
}
sort(all(crd));
crd.resize(unique(all(crd)) - crd.begin());
vector<int>ones;
for(int i=0;i<sz(crd);i++){
if(f[1][crd[i]]&1)ones.pb(i);
//cout<<crd[i]<<" ";
}
//cout<<'\n';
ll ans = 0;
ll carry = 0;
for(int i=sz(crd)-1;i>=0;i--){
ll need = f[2][crd[i]] + f[1][crd[i]]/2;
//cout<<need<<" "<<carry<<'\n';
ll tmp = min(need,carry);
carry -= tmp;
need -= tmp;
ll cnt = (need/k);
ans += cnt * 1LL * crd[i];
need -= cnt * k;
if(need){
ans+=crd[i];
carry+= k-need;
}
if(f[1][crd[i]] & 1){
if(carry){
carry--;
if(!ones.empty()){
int v = ones.back();
ones.pop_back();
f[1][crd[v]]--;
}
}else{
ans += crd[i];
carry = k-1;
ones.pop_back();
if(!ones.empty()){
int v = ones.back();
ones.pop_back();
f[1][crd[v]]--;
}
}
}
}
cout<<ans<<'\n';
for(int x:crd)f[1][x] = f[2][x] = 0;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 102ms
memory: 5432kb
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 24 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 19 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 25th lines differ - expected: '23', found: '24'