Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- class BI {
- vector<int> a;
- public:
- BI() {}
- void init(char *s) {
- static int p[] = { 1, 10, 100, 1000, 10000, 100000, 1000000 };
- int l = strlen(s) - 1;
- while (l >= 0) {
- int d = 0;
- for (int i = 0; i < 6; i++, l--)
- d += (l >= 0 ? s[l] - '0' : 0) * p[i];
- a.push_back(d);
- }
- }
- void print() {
- printf("%d", a[a.size() - 1]);
- for (int i = a.size() - 2; i >= 0; i--)
- printf("%06d", a[i]);
- }
- bool operator < (const BI &x) const {
- if (a.size() != x.a.size())
- return a.size() < x.a.size();
- for (int i = a.size() - 1; i >= 0; i--)
- if (a[i] != x.a[i])
- return a[i] < x.a[i];
- return 0;
- }
- BI operator + (const BI &x) const {
- BI r;
- int s = 0, o = 0;
- for (int i = 0; i < max(a.size(), x.a.size()); i++) {
- s = o;
- if (i < a.size())
- s += a[i];
- if (i < x.a.size())
- s += x.a[i];
- o = s / 1000000;
- r.a.push_back(s % 1000000);
- }
- if (o)
- r.a.push_back(o);
- return r;
- }
- } bi[1010];
- int n;
- char s[510];
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- scanf("%d\n", &n);
- for (int i = 0; i < n; i++) {
- scanf("%s\n", s);
- bi[i].init(s);
- }
- sort(&bi[0], &bi[n]);
- for (int i = 0; i < n - 2; i++) {
- for (int j = i + 1; j < n - 1; j++) {
- BI sum = bi[i] + bi[j];
- int l = j + 1, r = n - 1;
- while (l + 1 < r) {
- int m = l + (r - l) / 2;
- if (bi[m] < sum)
- l = m;
- else
- r = m;
- }
- if (bi[l] < sum && bi[i] < bi[j] + bi[l] && bi[j] < bi[i] + bi[l]) {
- bi[i].print();
- printf(" ");
- bi[j].print();
- printf(" ");
- bi[l].print();
- return 0;
- }
- if (bi[r] < sum && bi[i] < bi[j] + bi[r] && bi[j] < bi[i] + bi[r]) {
- bi[i].print();
- printf(" ");
- bi[j].print();
- printf(" ");
- bi[r].print();
- return 0;
- }
- }
- }
- printf("0 0 0");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement