Accepted
Code
#include<bits/stdc++.h>
using namespace std;
long long cnt=0;
bool ok=false;
int a,b,c;
int main()
{
//ofstream file("output10.txt");
long long a,b,c,X,n; cin>>X>>a>>b>>c>>n;
int x=(n/a)+1, y=(n/b)+1, z=(n/c)+1;
int cnt=1000000000;
for(int i=0;i<=x;i++)
{
for(int j=0;j<=y;j++)
{
for(int k=0;k<=z;k++)
{
if(a*i+b*j+c*k+X == n)
{
ok=true;
cnt=min(cnt,i+j+k);
}
}
}
}
if(ok)
{
cout<<"YES"<<endl;
//file<<"YES"<<endl;
cout<<cnt<<endl;
}
else cout<<"NO"<<endl; //file<<"NO"<<endl;}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1028 Magical box and spell
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-02-01 17:19:58
- Judged At
- 2024-11-11 03:43:25
- Judged By
- Score
- 100
- Total Time
- 3ms
- Peak Memory
- 532.0 KiB