QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22382 | #2544. Flatland Currency | George_Plover# | TL | 3ms | 3756kb | C++20 | 1.5kb | 2022-03-09 16:51:27 | 2022-04-30 00:58:55 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 110000
#define LL long long
using namespace std;
int n;
LL m;
int a[MAXN];
int v[MAXN];
LL q[5][MAXN];
int loc[5];
int cnt[5];
int main()
{
scanf("%d%lld",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]%5)
{
v[i]=5-a[i]%5;
a[i]+=v[i];
q[v[i]][++loc[v[i]]]=a[i];
}
}
int ans=m%5;
m-=ans;
for(int i=1;i<=4;i++){
sort(q[i]+1,q[i]+loc[i]+1);
cnt[i]=1;
}
LL w=m;
while(1)
{
bool flag=0;
int num;
for(int i=1;i<=4;i++)
{
if(w<q[i][cnt[i]] || cnt[i]>loc[i])continue;
else if(!flag)
{
num=i;flag=1;
}
else if(1ll * i * q[num][cnt[num]] <= 1ll * num * q[i][cnt[i]])
{
num=i;
}
}
if(!flag)break;
w-=q[num][cnt[num]++];
}
for(int i=1;i<=4;i++)cnt[i]--;
for(int i=1;i<=4;i++)
for(int j=1;j<=loc[i];j++)
q[i][j]+=q[i][j-1];
int out=ans;
for(int i=0;i<=loc[1];i++)
for(int j=0;j<=loc[2];j++)
for(int k=0;k<=loc[3];k++)
for(int l=0;l<=loc[4];l++)
{
int v = i + 2*j +3*k +4*l;
LL sp = q[1][i] + q[2][j] + q[3][k] + q[4][l];
if(sp<=m)
out=max(out,ans+v);
}
cout<<out<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3756kb
input:
5 57 9 14 31 18 27
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3736kb
input:
4 50 11 11 11 11
output:
12
result:
ok answer is '12'
Test #3:
score: -100
Time Limit Exceeded
input:
100000 89648823509660 921733427 402270498 51157221 585477094 435728758 913951087 580580944 557082810 585086423 837912728 799129405 867009344 751591136 714946046 464999915 256043168 416678301 183246216 569365122 479031618 435168577 31068363 903791719 497652990 960987871 223120213 395437892 112869678 ...