题目一般风格:
模板代码:
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 5e5+5; ll dis[maxn]; int n; ll l , r; int a[30]; bool flag[maxn]; queue<int> q; void spfa() { for(int i=0;i<a[1];i++)dis[i] = 1e18; q.push(0);flag[0] = 1,dis[0] = 0; while(q.size()) { int x = q.front();q.pop();flag[x] = 0; for(int i=2;i<=n;i++){ int o = (x+a[i])%a[1]; if(dis[o] > dis[x] + a[i]){ dis[o] = dis[x] + a[i]; if(!flag[o]) q.push(o),flag[o] = 1; } } } } int main() { scanf("%d%lld%lld",&n,&l,&r); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n); spfa(); ll ans = 0; for(int i=0;i<a[1];i++){ if(dis[i] <= r){ if(dis[i] >= l) ans += ((r-dis[i])/a[1]+1); else{ ans += ((r-dis[i])/a[1]+1); ans -= (l-dis[i]+a[1]-1)/a[1]; } } } printf("%lld\n",ans); return 0; }
```