不理解 哪里的问题

P1182 数列分段 Section II

Just_Love_You @ 2023-12-19 15:06:02

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define double long double
using namespace std;
constexpr int N=1e6+10;
constexpr int mod=1e16+10;
void solve()
{
    int n,m;
    cin >> n >> m;
    vector<int> f(n);
    for(int i=0;i<n;i++)
    {
        cin >> f[i];
    }
    int l=-mod;
    int r=mod;
    int mid;
    while(r-l^1)
    {
        mid=l+(r-l>>1);
        int cnt=1;
        int num=0;
        for(int i=0;i<n;i++)
        {
            if(num+f[i]>mid)
            {
                cnt++;
                num=f[i];
            }else
            {
                num+=f[i];
            }
        }
        if(cnt>m)
        {
            l=mid;
        }else
        {
            r=mid;
        }
    }
    cout << r << endl;
}
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    // int o;
    // cin >> o;
    // while(o--)
    solve();
    return 0;
}
//
//⠀⠀⠀             ⠀⢸⣿⣿⣿⠀⣼⣿⣿⣦⡀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀ ⠀⢸⣿⣿⡟⢰⣿⣿⣿⠟⠁
//⠀⠀⠀⠀⠀⠀⠀⢰⣿⠿⢿⣦⣀⠀⠘⠛⠛⠃⠸⠿⠟⣫ ⣴⣶⣾⡆
//⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀⠉⢿⣦⡀⠀⠀⠀⠀⠀⠀ ⠛⠿⠿⣿⠃
//⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣦⠀⠀⠹⣿⣶⡾⠛⠛⢷⣦⣄⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀⠀⠈⠉⣀⡀⠀ ⠀⠙⢿⡇
//⠀⠀⠀⠀⠀⠀⢀⣠⣴⡿⠟⠋⠀⠀⢠⣾⠟⠃⠀⠀⠀⢸⣿⡆
//⠀⠀⠀⢀⣠⣶⡿⠛⠉⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⢸⣿⠇
//⢀⣠⣾⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⢀⣼⣧⣀⠀⠀⠀⢀⣼⠇
//⠈⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠋⠙⠛⠛⠛⠛⠛⠁
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣾⡿⠋⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⢾⠿⠋⠀
//

by FurukawaNagisa @ 2023-12-19 15:17:26

10 5

10 2 3 3 3 3 3 3 3 3

帮你找了组hack


by Just_Love_You @ 2023-12-19 17:04:18

@FurukawaNagisa 感谢感谢


by Just_Love_You @ 2023-12-19 17:05:00

如果f[i]>mid 直接改变l=mid就好


by pbcoding @ 2024-01-17 21:22:33

123456


|