Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* NAME: PANAGIOTIS KOSTOPANAGIOTIS
- * TASK: OPERATORS
- * LANG: C++
- */
- #include <cstdio>
- #include <vector>
- #include <cmath>
- int main()
- {
- freopen("operators.in","r",stdin);
- freopen("operators.out","w",stdout);
- long N,current=0,num[2],min=1000000001;
- scanf("%d\n",&N);
- std::vector<long> neg;
- for(int i=0; scanf("%d ",¤t) != EOF && i<N; ++i) {
- if(current>0 && !i) {
- num[0]=current;
- scanf("%d ", &num[1]);
- break;
- }
- if(current<0)
- neg.push_back(current);
- while (current>0 && neg.size()) {
- if(fabs(neg.back()+current)<min) {
- num[0]=neg.back();
- num[1]=current;
- min=fabs(num[0]+num[1]);
- }
- if(fabs(neg.back())>current)
- break;
- neg.pop_back();
- }
- if(neg.size()==0 || num[0]+num[1]==0)
- break;
- }
- if(neg.size()==N) {
- for(int i=0; i<2; ++i) {
- num[1-i]=neg.back();
- neg.pop_back();
- }
- }
- printf("%d %d\n", num[0],num[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement