Problem Statement We have a sequence of N N positive integers: A = ( A 1 , … , A N )…
- User
Problem Statement We have a sequence of N N positive integers: A
( A 1 , … , A N ) A=(A 1 ,…,A N ). Let B B be the concatenation of 1 0 100 10 100 copies of A A.
Consider summing up the terms of B B from left to right. When does the sum exceed X X for the first time? In other words, find the minimum integer k k such that:
∑ i
1 k B i
X i=1 ∑ k B i
X.
Constraints 1 ≤ N ≤ 1 0 5 1≤N≤10 5
1 ≤ A i ≤ 1 0 9 1≤A i ≤10 9
1 ≤ X ≤ 1 0 18 1≤X≤10 18
All values in input are integers. Input Input is given from Standard Input in the following format:
N N A 1 A 1
… … A N A N
X X Output Print the answer.
Sample 1 Inputcopy Outputcopy 3 3 5 2 26 8 We have B
( 3 , 5 , 2 , 3 , 5 , 2 , 3 , 5 , 2 , … ) B=(3,5,2,3,5,2,3,5,2,…). ∑ i
1 8 B i
28
26 i=1 ∑ 8 B i =28>26 holds, but the condition is not satisfied when k k is 7 7 or less, so the answer is 8 8.
Sample 2 Inputcopy Outputcopy 4 12 34 56 78 1000 23 Bu sualda#include <bits/stdc++.h>
using namespace std;
#define ll long long #define ld long double #define endl '\n' #define pb push_back #define speedyboy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) x.begin() , x.end() #define F first #define S second #define pll pair<ll , ll> #define pss pair<string , string> #define YES cout << "YES" << endl; #define NO cout << "NO" << endl;
ll i , j , k; const ll sz = 5e5 + 5 , INF = 1e18 , MOD = 998244353; ll a[sz];
void solve(){ ll n , ans = 0, sum = 0; cin >> n; for(i = 1 ; i <= n ; i++){ cin >> a[i]; sum += a[i]; } cin >> k; if(k == sum){ cout << n << endl; } if(k < sum){ for(i = 1; i <= n ; i++){ k -= a[i]; ans++; if(k <= 0){ break; } } cout << ans << endl; } else{ ll x = k / sum; ll y = k - x * sum; ans += x * n; for(i = 1 ; i <= n; i++){ y -= a[i]; ans++; if(y <= 0){ break; } } cout << ans << endl; } }
signed main(){ speedyboy; ll t = 1; //cin >> t; while(t--){ solve(); } } kodum niyə səhvdir?Azərbaycanca danış
- Assistant