0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#796. [NOIP福建夏令营]最小和

https://sjzezoj.com/submission/40495
This commit is contained in:
Baoshuo Ren 2021-10-19 21:49:12 +08:00 committed by Baoshuo Ren
parent daad3aeb18
commit 5699f161cf
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

32
S2OJ/796/796.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
int n, x, maxx = -1;
long long mind = 0x3f3f3f3f3f3f3f3f;
struct node {
int x;
long long d;
} s[100005];
pair<long long, int> a[100005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
a[i].first = a[i - 1].first + x;
a[i].second = i;
}
sort(a, a + 1 + n);
for (int i = 2; i <= n; i++) {
if (a[i].first - a[i - 1].first < mind || a[i].first - a[i - 1].first == mind && abs(a[i].second - a[i - 1].second) > maxx) {
mind = a[i].first - a[i - 1].first;
maxx = abs(a[i].second - a[i - 1].second);
}
}
cout << mind << endl
<< maxx << endl;
return 0;
}