Submission #70977829
Source Code Expand
#include<bits/stdc++.h>
//bool Mst;
using namespace std;
namespace wyzfastio
{
#ifndef LOCAL
namespace __getchar{const int bufsize=1<<22;char buf[bufsize],*p1=buf,*p2=buf;inline char getchar(){return (p1==p2&&(p2=(p1=buf)+fread(buf,1,bufsize,stdin),p1==p2))?EOF:(*p1++);}}using __getchar::getchar;namespace __putchar{const int bufsize=1<<22;char buf[bufsize],*p=buf;inline void putchar(const char ch){if(p-buf==bufsize) fwrite(buf,1,bufsize,stdout),p=buf;*p++=ch;}inline void flush(){fwrite(buf,1,p-buf,stdout),p=buf;}}using __putchar::putchar;using __putchar::flush;namespace __flusher{struct Flusher{Flusher(){}~Flusher(){flush();}}flusher;}
#define endl "\n"
#else
void flush(){}
#define endl wyzfastio::oshelper::_endl
#endif
std::string bool_str[2]={"false","true"};int double_mx=12;struct istream{void tie([[maybe_unused]]int x){}};struct ostream{void tie([[maybe_unused]]int x){}};istream in;ostream out;
istream &operator>>(istream &in,char &s){s=getchar();while(s==' '||s=='\n'||s=='\r')s=getchar();return in;}istream &operator>>(istream &in,std::string &s){char ch=getchar();s.clear();while(ch==' '||ch=='\n'||ch=='\r')ch=getchar();while(!(ch==' '||ch=='\n'||ch=='\r'||ch==EOF))s+=ch,ch=getchar();return in;}istream &operator>>(istream &in,__int128 &x){char ch=getchar();int o=0;__int128 r=0;while(ch<'0'||ch>'9'){if(ch=='-')o^=1;ch=getchar();}while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=o?-r:r;return in;}istream &operator>>(istream &in,unsigned __int128 &x){char ch=getchar();__int128 r=0;while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=r;return in;}
ostream &operator<<(ostream &out,const char x){putchar(x);return out;}ostream &operator<<(ostream &out,const char *s){while(*s!='\0'&&*s!=EOF)putchar(*s),s++;return out;}ostream &operator<<(ostream &out,std::string s){for(char ch:s)putchar(ch);return out;}ostream &operator<<(ostream &out,__int128 x){static int __stk[66];int top=0,op=1-((x<0)<<1);if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10)*op,x/=10;if(op==-1)putchar('-');while(top)putchar(__stk[--top]+'0');return out;}ostream &operator<<(ostream &out,unsigned __int128 x){static int __stk[66];int top=0;if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10),x/=10;while(top)putchar(__stk[--top]+'0');return out;}
template<typename _Tp>inline typename std::enable_if<std::is_integral<_Tp>::value&&!std::is_same<_Tp,bool>::value,istream &>::type operator>>(istream &in,_Tp &x){char ch=getchar();int o=0;_Tp r=0;while(ch<'0'||ch>'9'){if(ch=='-')o^=1;ch=getchar();}while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=o?-r:r;return in;}template<typename _Tp>inline typename std::enable_if<std::is_same<_Tp,bool>::value,istream &>::type operator>>(istream &in,_Tp &x){int r;in>>r;x=r;return in;}template<typename _Tp>inline typename std::enable_if<std::is_floating_point<_Tp>::value,istream &>::type operator>>(istream &in,_Tp &x){_Tp r=0,p=1;int op=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')op=-op;ch=getchar();}while(ch>='0'&&ch<='9'){r=r*10+ch-'0';ch=getchar();}if(ch=='.'){ch=getchar();while(ch>='0'&&ch<='9')r+=(p*=0.1)*(ch-'0'),ch=getchar();}x=r*op;return in;}
template<typename _Tp>inline typename std::enable_if<std::is_integral<_Tp>::value&&!std::is_same<_Tp,bool>::value,ostream &>::type operator<<(ostream &out,_Tp x){static int __stk[33];int top=0,op=1-((x<0)<<1);if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10)*op,x/=10;if(op==-1)putchar('-');while(top)putchar(__stk[--top]+'0');return out;}template<typename _Tp>inline typename std::enable_if<std::is_same<_Tp,bool>::value,ostream &>::type operator<<(ostream &out,_Tp x){out<<bool_str[x];return out;}template<typename _Tp>inline typename std::enable_if<std::is_floating_point<_Tp>::value,ostream &>::type operator<<(ostream &out,_Tp x){if(x<0)putchar('-'),x=-x;static int __stk[233];int top=0;for(int i=0;i<double_mx;i++)x*=10;x=std::floor(x+0.5);for(_Tp y;x>=1;)y=std::floor(x/10),__stk[top++]=x-y*10,x=y;while(top<=double_mx)__stk[top++]=0;while(top>double_mx)putchar(__stk[--top]+'0');putchar('.');while(top)putchar(__stk[--top]+'0');return out;}
namespace oshelper{struct ostreamhelper{};struct endler{};endler _endl;ostreamhelper set_bool_str(const std::string str_false,const std::string str_true){bool_str[0]=str_false,bool_str[1]=str_true;return ostreamhelper();}ostreamhelper set_precision(int precision){double_mx=precision;return ostreamhelper();}ostream &operator<<(ostream &out,[[maybe_unused]]ostreamhelper outhelper){return out;}ostream &operator<<(ostream &out,[[maybe_unused]]endler _endl){out<<"\n",flush();return out;}}
#define cin wyzfastio::in
#define cout wyzfastio::out
}
using ll=long long;
using ld=long double;
#define int ll
using pii=pair<int,int>;
const int N=2e5+5;
int a[N];
//bool Med;
signed main()
{
// cerr<<"Memory Size: "<<abs((&Med)-(&Mst))/1024.0/1024<<" MB\n";
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
int n,x,y,ans=0,res=1e18;
cin>>n>>x>>y;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) if(a[i]*x%(y-x)!=a[1]*x%(y-x)) return cout<<"-1\n",0;
for(int i=1;i<=n;i++) res=min(res,a[i]*y);
if(res%(y-x)!=a[1]*x%(y-x)) res-=y-x-a[1]*x%(y-x);
for(int i=1;i<=n;i++) if(res<a[i]*x) return cout<<"-1\n",0;
for(int i=1;i<=n;i++) ans+=(res-a[i]*x)/(y-x);
cout<<ans<<"\n";
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Candy Tribulation |
| User |
wangyizhi |
| Language |
C++23 (GCC 15.2.0) |
| Score |
350 |
| Code Size |
5351 Byte |
| Status |
AC |
| Exec Time |
6 ms |
| Memory |
7252 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
350 / 350 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All |
00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-01.txt |
AC |
1 ms |
3540 KiB |
| 00-sample-02.txt |
AC |
1 ms |
3516 KiB |
| 00-sample-03.txt |
AC |
1 ms |
3404 KiB |
| 01-01.txt |
AC |
3 ms |
5268 KiB |
| 01-02.txt |
AC |
2 ms |
3996 KiB |
| 01-03.txt |
AC |
3 ms |
5660 KiB |
| 01-04.txt |
AC |
4 ms |
5820 KiB |
| 01-05.txt |
AC |
4 ms |
5688 KiB |
| 01-06.txt |
AC |
6 ms |
7252 KiB |
| 01-07.txt |
AC |
6 ms |
7160 KiB |
| 01-08.txt |
AC |
6 ms |
7124 KiB |
| 01-09.txt |
AC |
6 ms |
7092 KiB |
| 01-10.txt |
AC |
6 ms |
7132 KiB |
| 01-11.txt |
AC |
5 ms |
7060 KiB |
| 01-12.txt |
AC |
5 ms |
7068 KiB |
| 01-13.txt |
AC |
5 ms |
6264 KiB |
| 01-14.txt |
AC |
6 ms |
7188 KiB |
| 01-15.txt |
AC |
5 ms |
7060 KiB |
| 01-16.txt |
AC |
6 ms |
6676 KiB |
| 01-17.txt |
AC |
6 ms |
7104 KiB |
| 01-18.txt |
AC |
6 ms |
7036 KiB |
| 01-19.txt |
AC |
5 ms |
6740 KiB |
| 01-20.txt |
AC |
6 ms |
7000 KiB |
| 01-21.txt |
AC |
6 ms |
7120 KiB |
| 01-22.txt |
AC |
5 ms |
6920 KiB |
| 01-23.txt |
AC |
5 ms |
7100 KiB |
| 01-24.txt |
AC |
5 ms |
6988 KiB |
| 01-25.txt |
AC |
4 ms |
6416 KiB |
| 01-26.txt |
AC |
3 ms |
5440 KiB |
| 01-27.txt |
AC |
4 ms |
6612 KiB |
| 01-28.txt |
AC |
5 ms |
6264 KiB |
| 01-29.txt |
AC |
5 ms |
7124 KiB |
| 01-30.txt |
AC |
5 ms |
7092 KiB |
| 01-31.txt |
AC |
4 ms |
5812 KiB |
| 01-32.txt |
AC |
6 ms |
7148 KiB |
| 01-33.txt |
AC |
6 ms |
6988 KiB |
| 01-34.txt |
AC |
5 ms |
6288 KiB |
| 01-35.txt |
AC |
6 ms |
7104 KiB |
| 01-36.txt |
AC |
6 ms |
7092 KiB |
| 01-37.txt |
AC |
3 ms |
5496 KiB |
| 01-38.txt |
AC |
5 ms |
7188 KiB |
| 01-39.txt |
AC |
5 ms |
7160 KiB |
| 01-40.txt |
AC |
4 ms |
6520 KiB |
| 01-41.txt |
AC |
4 ms |
6196 KiB |
| 01-42.txt |
AC |
3 ms |
5652 KiB |
| 01-43.txt |
AC |
5 ms |
7160 KiB |