Submission #70964851
Source Code Expand
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
ll n;
ll x,y;
cin>>n>>x>>y;
vector<ll> a(n);
for(auto &x : a)
cin>>x;
ll g= __gcd(x, y);
ll k=(y-x)/g;
for(int i=1;i<n;i++)
if((a[i]-a[0])%k!=0){
cout<<-1<<endl;
return;
}
ll mod=y-x;
ll t=(a[0]*x)%mod;
ll mx=LLONG_MAX;
for(ll a : a) mx=min(mx,a*y);
ll rem=mx%mod;
ll diff=(rem-t+mod)%mod;
ll W=mx-diff;
if(W < *max_element(a.begin(),a.end())*x){
cout<<-1<<endl;
return;
}
ll t2 = 0;
for(ll a : a)
t2+=(W-a*x)/(y-x);
cout<<t2<<endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
//cin>>t;
t=1;
while(t--) solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Candy Tribulation |
| User | Luongdung |
| Language | C++23 (GCC 15.2.0) |
| Score | 350 |
| Code Size | 868 Byte |
| Status | AC |
| Exec Time | 10 ms |
| Memory | 5076 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 | 3488 KiB |
| 00-sample-02.txt | AC | 1 ms | 3444 KiB |
| 00-sample-03.txt | AC | 1 ms | 3444 KiB |
| 01-01.txt | AC | 5 ms | 4056 KiB |
| 01-02.txt | AC | 2 ms | 3544 KiB |
| 01-03.txt | AC | 6 ms | 4368 KiB |
| 01-04.txt | AC | 6 ms | 4344 KiB |
| 01-05.txt | AC | 7 ms | 4944 KiB |
| 01-06.txt | AC | 10 ms | 5076 KiB |
| 01-07.txt | AC | 10 ms | 4948 KiB |
| 01-08.txt | AC | 10 ms | 4948 KiB |
| 01-09.txt | AC | 10 ms | 4760 KiB |
| 01-10.txt | AC | 10 ms | 4952 KiB |
| 01-11.txt | AC | 9 ms | 4872 KiB |
| 01-12.txt | AC | 9 ms | 4944 KiB |
| 01-13.txt | AC | 7 ms | 4624 KiB |
| 01-14.txt | AC | 10 ms | 5012 KiB |
| 01-15.txt | AC | 9 ms | 4932 KiB |
| 01-16.txt | AC | 9 ms | 4948 KiB |
| 01-17.txt | AC | 9 ms | 4852 KiB |
| 01-18.txt | AC | 10 ms | 5004 KiB |
| 01-19.txt | AC | 9 ms | 4560 KiB |
| 01-20.txt | AC | 10 ms | 4932 KiB |
| 01-21.txt | AC | 10 ms | 4928 KiB |
| 01-22.txt | AC | 9 ms | 4800 KiB |
| 01-23.txt | AC | 9 ms | 4924 KiB |
| 01-24.txt | AC | 9 ms | 5076 KiB |
| 01-25.txt | AC | 7 ms | 4628 KiB |
| 01-26.txt | AC | 6 ms | 4156 KiB |
| 01-27.txt | AC | 7 ms | 4600 KiB |
| 01-28.txt | AC | 7 ms | 4248 KiB |
| 01-29.txt | AC | 9 ms | 4924 KiB |
| 01-30.txt | AC | 9 ms | 4944 KiB |
| 01-31.txt | AC | 7 ms | 4436 KiB |
| 01-32.txt | AC | 10 ms | 4952 KiB |
| 01-33.txt | AC | 10 ms | 4932 KiB |
| 01-34.txt | AC | 8 ms | 4560 KiB |
| 01-35.txt | AC | 10 ms | 4972 KiB |
| 01-36.txt | AC | 10 ms | 4932 KiB |
| 01-37.txt | AC | 6 ms | 4180 KiB |
| 01-38.txt | AC | 9 ms | 4924 KiB |
| 01-39.txt | AC | 9 ms | 5004 KiB |
| 01-40.txt | AC | 7 ms | 4564 KiB |
| 01-41.txt | AC | 7 ms | 4560 KiB |
| 01-42.txt | AC | 5 ms | 4368 KiB |
| 01-43.txt | AC | 9 ms | 5008 KiB |