题意:初始有t元,每次从1开始买,从1到n依次有n个人,每个人的东西价格为a[i],该人依次能买就买,到n之后再回到1从头开始,问最后能买到的东西数量
n<=2e5,t<=1e18,a[i]<=1e9
思路:显然购买是有周期的,每次周期变化都会少至少一个人,所以至多进行n次周期的变化
1 #include<cstdio> 2 #include<cstring> 3 #include<string> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 #include<map> 8 #include<set> 9 #include<queue> 10 #include<vector> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned int uint; 14 typedef unsigned long long ull; 15 typedef pair<int,int> PII; 16 typedef vector<int> VI; 17 #define fi first 18 #define se second 19 #define MP make_pair 20 #define N 200010 21 #define M 200 22 #define MOD 998244353 23 #define eps 1e-8 24 #define pi acos(-1) 25 #define oo 1000000000 26 27 ll a[N]; 28 29 int main() 30 { 31 //freopen("D.in","r",stdin); 32 //freopen("D.out","w",stdout); 33 int n; 34 ll t; 35 scanf("%d%lld",&n,&t); 36 ll mn=oo; 37 for(int i=1;i<=n;i++) 38 { 39 scanf("%lld",&a[i]); 40 mn=min(mn,a[i]); 41 } 42 43 ll ans=0; 44 while(t>=mn) 45 { 46 ll s=0; 47 ll k=0; 48 for(int i=1;i<=n;i++) 49 if(t>=a[i]) 50 { 51 t-=a[i]; 52 s++; 53 k+=a[i]; 54 } 55 ans+=s+t/k*s; 56 t%=k; 57 } 58 printf("%lld ",ans); 59 return 0; 60 }