欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CodeForces - 1073D(模拟)

程序员文章站 2022-03-14 19:40:38
...

题解:

每一圈都是有规律,像是一层一层的,也就是每一层去掉一个最大值,最多就n层。

#include <algorithm>
#include  <iostream>
#include   <cstdlib>
#include   <cstring>
#include    <cstdio>
#include    <string>
#include    <vector>
#include    <bitset>
#include     <stack>
#include     <cmath>
#include     <deque>
#include     <queue>
#include      <list>
#include       <set>
#include       <map>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define line printf("---------------------------\n")
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
using namespace std;
typedef long long ll;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const int maxn = 200000+10;

ll a[maxn];
ll n, T;

int main(){
	cin>>n>>T;
	ll minn = 1e18;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		minn = min(minn, a[i]);
	}
	ll ans = 0;
	while(T >= minn){
		ll temp = 0, sum = 0;
		for(int i = 0; i < n; i++){
			if(T >= a[i]){
				T -= a[i];
				temp++;
				sum += a[i];
			}
		} 
		ans += (T/sum+1)*temp;
		T %= sum;
	}
	cout<<ans<<endl;
}

 

相关标签: 模拟