Submission #70965601
Source Code Expand
#include<bits/stdc++.h>
#define ll long long
#define REP(i,l,r) for(int i=(l);i<=(r);i++)
#define PER(i,r,l) for(int i=(r);i>=(l);i--)
using namespace std;
inline int read(){
int x=0,f=1;
char c=getchar();
while(!isdigit(c)){
if(c=='-')f=-1;
c=getchar();
}
while(isdigit(c)){
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
}
return x*f;
}
void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const int N=2e5+5;
int gcd(int a,int b){
if(!b)return a;
return gcd(b,a%b);
}
int n,a[N],x,y;
int main(){
n=read(),x=read(),y=read();
REP(i,1,n)a[i]=read();
sort(a+1,a+n+1);
int d=(y-x)/gcd(x,y-x);
REP(i,2,n)if((a[i]-a[i-1])%d){
write(-1),putchar('\n');
return 0;
}
if(1ll*y*a[1]<1ll*x*a[n]){
write(-1),putchar('\n');
return 0;
}
ll res=a[1];int p=a[1];
REP(i,2,n){
p-=1ll*(a[i]-a[i-1])*x/(y-x);
res+=p;
}
write(res),putchar('\n');
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Candy Tribulation |
| User | Yuzimy |
| Language | C++23 (GCC 15.2.0) |
| Score | 350 |
| Code Size | 1085 Byte |
| Status | AC |
| Exec Time | 19 ms |
| Memory | 4336 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 | 3472 KiB |
| 00-sample-02.txt | AC | 1 ms | 3560 KiB |
| 00-sample-03.txt | AC | 1 ms | 3472 KiB |
| 01-01.txt | AC | 9 ms | 3940 KiB |
| 01-02.txt | AC | 3 ms | 3648 KiB |
| 01-03.txt | AC | 11 ms | 3912 KiB |
| 01-04.txt | AC | 12 ms | 4080 KiB |
| 01-05.txt | AC | 4 ms | 4328 KiB |
| 01-06.txt | AC | 9 ms | 4216 KiB |
| 01-07.txt | AC | 9 ms | 4128 KiB |
| 01-08.txt | AC | 18 ms | 4228 KiB |
| 01-09.txt | AC | 18 ms | 4168 KiB |
| 01-10.txt | AC | 18 ms | 4308 KiB |
| 01-11.txt | AC | 17 ms | 4240 KiB |
| 01-12.txt | AC | 18 ms | 4184 KiB |
| 01-13.txt | AC | 13 ms | 4200 KiB |
| 01-14.txt | AC | 18 ms | 4148 KiB |
| 01-15.txt | AC | 17 ms | 4244 KiB |
| 01-16.txt | AC | 16 ms | 4308 KiB |
| 01-17.txt | AC | 19 ms | 4176 KiB |
| 01-18.txt | AC | 18 ms | 4228 KiB |
| 01-19.txt | AC | 16 ms | 4220 KiB |
| 01-20.txt | AC | 18 ms | 4328 KiB |
| 01-21.txt | AC | 18 ms | 4308 KiB |
| 01-22.txt | AC | 17 ms | 4168 KiB |
| 01-23.txt | AC | 17 ms | 4168 KiB |
| 01-24.txt | AC | 18 ms | 4216 KiB |
| 01-25.txt | AC | 14 ms | 4112 KiB |
| 01-26.txt | AC | 10 ms | 3984 KiB |
| 01-27.txt | AC | 15 ms | 4216 KiB |
| 01-28.txt | AC | 14 ms | 4116 KiB |
| 01-29.txt | AC | 17 ms | 4336 KiB |
| 01-30.txt | AC | 18 ms | 4220 KiB |
| 01-31.txt | AC | 12 ms | 4012 KiB |
| 01-32.txt | AC | 18 ms | 4168 KiB |
| 01-33.txt | AC | 18 ms | 4224 KiB |
| 01-34.txt | AC | 14 ms | 4208 KiB |
| 01-35.txt | AC | 18 ms | 4300 KiB |
| 01-36.txt | AC | 18 ms | 4168 KiB |
| 01-37.txt | AC | 10 ms | 3912 KiB |
| 01-38.txt | AC | 17 ms | 4336 KiB |
| 01-39.txt | AC | 18 ms | 4336 KiB |
| 01-40.txt | AC | 14 ms | 4160 KiB |
| 01-41.txt | AC | 13 ms | 4172 KiB |
| 01-42.txt | AC | 10 ms | 3920 KiB |
| 01-43.txt | AC | 18 ms | 4220 KiB |