Pagini recente » Cod sursa (job #10572) | Cod sursa (job #934104) | Cod sursa (job #420710) | Cod sursa (job #511319) | Cod sursa (job #3243354)
#include <bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
//#define fin cin
//#define fout cout
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
int n;
vector<int> v(200001);
vector<bool> hasBeenStart(200001);
struct a {
int value;
int index;
int length;
friend bool operator<(a&me , a& other) {
return me.value < other.value;
}
friend bool operator==(a&me , a& other) {
return me.value == other.value;
}
friend ostream& operator<<(ostream& os, const a& me) {
os << me.value << ' ' << me.index << ' ' << me.length;
return os;
}
};
int main() {
fin >> n;
for (int i = 1; i <= n; i++) {
bool type;
fin >> v[i] >> type;
if (!type) {
v[i] *= -1;
}
}
a curr, ans;
curr = ans = {v[1],1,1};
for (int i = 2; !hasBeenStart[curr.index] and curr.length <= n; i++, i = i > n ? 1 : i, curr.length++) {
if (curr.value + v[i] >= v[i]) {
curr.value += v[i];
if (ans < curr) {
ans = curr;
} else if (ans == curr and ans.length < curr.length or ans.index < curr.index) {
ans = curr;
}
} else {
hasBeenStart[curr.index] = true;
curr.value = v[i];
curr.length = 1;
curr.index = i;
if (ans < curr) {
ans = curr;
} else if (ans == curr and ans.length < curr.length or ans.index < curr.index) {
ans = curr;
}
}
}
fout << ans;
return 0;
}