QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688696 | #7744. Elevator | JEdward | WA | 36ms | 5624kb | C++20 | 2.4kb | 2024-10-30 12:40:50 | 2024-10-30 12:40:55 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
#define endl '\n'
#define lowbit(x) (x)&(-x)
#define all(s) s.begin(), s.end()
#define pii pair<int,int>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define here system("pause")
using namespace std;
template <class T>
inline void read(T &x){
x = 0;
char c = getchar();
bool f = 0;
for (; !isdigit(c); c = getchar()) f ^= (c == '-');
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
x = f ? -x : x;
}
template <class T>
inline void write(T x){
if (x < 0) putchar('-'), x = -x;
if (x < 10) putchar(x + 48);
else write(x / 10), putchar(x % 10 + 48);
}
template<typename T> void chkmin(T& lhs, const T& rhs) { lhs = lhs > rhs ? rhs : lhs; }
template<typename T> void chkmax(T& lhs, const T& rhs) { lhs = lhs < rhs ? rhs : lhs; }
const int N = 2e5 + 5;
const int mod = 998244353;
const int INF = 8e18 + 9;
const double eps = 1e-7;
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}
mt19937_64 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R) {
uniform_int_distribution<int> dist(L, R);
return dist(rnd);
}
inline void sol(){
int n, k;
cin >> n >> k;
vector<array<int, 3>> a(n);
int ans = 0;
for(int i=0;i<n;i++){
for(int j=0;j<3;j++){
cin >> a[i][j];
}
}
sort(all(a), [&](const array<int, 3> &lhs, const array<int, 3> &rhs){
return lhs[2] > rhs[2];
});
int pos = 0;
for(int i=0, j;i<n;i=j){
if(!a[i][0]){
j = i + 1;
continue;
}
int rest = k;
j = i;
while(j < n && rest >= a[j][0] * a[j][1]){
rest -= a[j][0] * a[j][1];
a[j++][0] = 0;
}
if(j == i){
int onetime = rest / a[j][1];
int times = a[i][0] / onetime;
ans += times * a[i][2];
a[i][0] -= times * onetime;
}else{
ans += a[i][2];
if(j < n){
int onetime = rest / a[j][1];
rest -= onetime * a[j][1];
a[j][0] -= onetime;
if(rest){
while(pos < n && (pos < j || !a[pos][0] || a[pos][2] == 2)){
++pos;
}
if(pos < n) a[pos][0]--;
}
}
}
}
cout << ans << endl;
}
signed main(){
IOS;
int tc = 1;
cout << fixed << setprecision(10);
cin >> tc;
while(tc--){
sol();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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: 36ms
memory: 5624kb
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 5 4 1 8 5 5 7 1 3 23 6 3 3 2 2 2 3 8 1 5 6 9 11 145 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 19 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 16th lines differ - expected: '6', found: '5'