为什么这个不过鸭!(给关注,大佬快九九孩子吧!Orz))
查看原帖
为什么这个不过鸭!(给关注,大佬快九九孩子吧!Orz))
1148832
LabmemNo_012LzTopic楼主2024/11/20 19:36
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
using namespace std;

multiset<long long>k;

long long a[1005] = { 0 };

int main()
{
    int n;
    long long ans = 100000000, kk;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= n; j++)
        {
            k.insert(a[j] - a[i - 1]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= n; j++)
        {
            auto p = k.find(a[j] - a[i - 1]);
            k.erase(p);
        }
        for (int j = 1; j <= i; j++)
        {
            kk = a[j] - a[i - 1];
            auto p = k.lower_bound(kk);
            if (p != k.end()) ans = min(ans, abs(*p - kk));
            if (p != k.begin()) p--, ans = min(ans, abs(*p - kk));
        }
    }
    cout << ans << endl;
    return 0;
}
2024/11/20 19:36
加载中...