River Locks

题目链接:Problem - D - Codeforces

向上取整+思维

向上取整操作:(A+B-1)/B 就是对 A/B 的向上取整

思路:

 

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    ll sum = 0;
    cin >> n;
    vector<ll>a(n + 1),pre(n+1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i], pre[i] = sum;
    }
    int T = 1;
    cin >> T;
    ll maxn = LLONG_MIN;
    for (int i = 1; i <= n; i++)
    {
     //pre[i]+i-1/i是向上取整操作 maxn
= max(maxn, (pre[i] + i - 1) / i); } while (T--) { int x; cin >> x; if (x < maxn)cout << -1 << endl; else cout << (pre[n] + x -1) / x << endl; } return 0; }

 

posted @ 2023-03-22 19:28  zhujio  阅读(26)  评论(0)    收藏  举报