QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548143 | #7744. Elevator | Bird# | WA | 38ms | 4336kb | C++14 | 1.7kb | 2024-09-05 15:52:16 | 2024-09-05 15:52:17 |
Judging History
answer
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#define N 100000
using namespace std;
int n,k,T;
vector<pair<int,int>> a[2];
int main()
{
for(scanf("%d",&T);T--;)
{
scanf("%d %d",&n,&k);
a[0].clear(),a[1].clear();
for(int i=1,c,w,f;i<=n;++i)
{
scanf("%d %d %d",&c,&w,&f);
a[w&1].push_back({f,c});
}
for(int i=0;i<2;++i)
sort(a[i].begin(),a[i].end(),greater<pair<int,int>>());
long long ans=0;
for(int i=0,j=0,c,w,nowk=0;i<a[0].size() || j<a[1].size();)
if(j==a[1].size() || (i<a[0].size() && a[0][i].first>=a[1][j].first && !(nowk&1)))
{
if(a[0][i].second*2<=nowk)
nowk-=a[0][i].second*2,a[0][i].second=0;
else a[0][i].second-=nowk/2,nowk=0;
ans+=a[0][i].second/(k/2)*a[0][i].first;
a[0][i].second%=k/2;
if(a[0][i].second) ans+=a[0][i].first,nowk=k-a[0][i].second*2;
++i;
}
else
{
if(nowk&1)
{
--nowk,--a[1][j].second;
if(!a[1][j].second) ++j;
continue;
}
if(a[1][j].second<=nowk)
nowk-=a[1][j].second,a[1][j].second=0;
else a[1][j].second-=nowk,nowk=0;
ans+=a[1][j].second/k*a[1][j].first;
a[1][j].second%=k;
if(a[1][j].second) ans+=a[1][j].first,nowk=k-a[0][i].second;
++j;
}
printf("%lld\n",ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3912kb
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: 38ms
memory: 4336kb
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 20 4 5 7 1 3 9 6 1 10 4 9 20 6 4 1 8 5 5 7 1 3 23 6 3 3 2 2 2 3 8 1 5 6 9 11 161 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 3rd lines differ - expected: '23', found: '20'