d031. 例題 P-3-7. 正整數序列之最接近的區間和 - TCFSH CIRC Judge

本文最後更新於:2024年1月12日 下午

d031. 例題 P-3-7. 正整數序列之最接近的區間和 - TCFSH CIRC Judge

AP325-d031.cpp

// Author : ysh
// 07/16/2022 Sat 14:55:13.37
// https://judge.tcirc.tw/ShowProblem?problemid=d031
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    map<int,int>m({{0,1}});
    int a,b;cin>>a>>b;
    int c = 0,mmax = 0;
    int last = 0;
    for(int i = 0;i<a;i++) {
        int now;cin>>now;
        now = last += now;
        auto found = m.lower_bound(now - b);
        if(found != m.end()) {
            if(now - found->first > mmax) {
                mmax = now - found->first;
                c = found->second;
            } else if(now - found->first == mmax) {
                c += found->second;
            }
        }
        m[now]++;
    }
    cout<<mmax<<"\n"<<c;
    return 0;
}

d031. 例題 P-3-7. 正整數序列之最接近的區間和 - TCFSH CIRC Judge
http://mysh212.github.io/algosolution/AP325-d031.cpp/
作者
ysh
發布於
2022年7月16日
更新於
2024年1月12日
許可協議