#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define inf 1e17
const int N=2e6;
int cur[N],pw[N];
signed main(){
int n,m;
cin>>n>>m;
vector<int>v;
for(int i=0;i<m;i++){
cin>>cur[i]>>pw[i];
}
if(n==2){
if(abs(cur[0]-cur[1])%pw[0]){
cout<<-1;
}
else{
cout<<abs(cur[0]-cur[1])/pw[0];
}
}
else{
int s=INT_MAX;
if(abs(cur[0]-cur[1])%pw[0]==0){
s=abs(cur[0]-cur[1])/pw[0];
}
int k=0;
bool u=0;
if(abs(cur[0]-cur[2])%pw[0]){
u=1;
}
else{
k+=abs(cur[0]-cur[2])/pw[0];
}
if(abs(cur[2]-cur[1])%pw[2]){
u=1;
}
else{
k+=abs(cur[1]-cur[2])/pw[2];
}
if(u==0){
s=min(s,k);
}
if(s==INT_MAX){
cout<<-1;
}
else{
cout<<s;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 8 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 8 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 8 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 8 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 8 |
3 |
Halted |
0 ms |
0 KB |
- |