#include <bits/stdc++.h>
using namespace std;
#define N 30001
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
int T, n, m, b[N], p[N], d[N];
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> b[i] >> p[i];
d[i] = 1e5;
}
d[0] = 0;
int x = 0;
vis[0] = 1;
vector <int> v;
for(int i = 1; i < m; i++) v.push_back(i);
while(sz(v) > 0){
int mn = 1e5, ind = x;
for(auto i : v){
int k = (abs(b[i]-b[x]));
if(d[i] < mn) ind = i;
mn = min(d[i],mn);
if(k % p[x] != 0) continue;
d[i] = min(d[x] + (k/p[x]), d[i]);
if(d[i] < mn) ind = i;
mn = min(d[i],mn);
}
if(x == ind) break;
x = ind;
if(x == 1) break;
for(int i = 0; i < sz(v); i++){
if(v[i] == ind){
v.erase(v.begin() + i);
break;
}
}
}
if(d[1] == 1e5) d[1] = -1;
cout << d[1];
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:23:5: error: 'vis' was not declared in this scope
23 | vis[0] = 1;
| ^~~