CF 558A Lala Land and Apple Trees

Source: Internet
Author: User

#include <stdio.h>#include <algorithm>#include <string.h>using namespace STD;structdata{intXintA;}; Data l[1024x768],r[1024x768];BOOLC1 (data Q,data p) {returnq.x<p.x;}BOOLC2 (data Q,data p) {returnq.x>p.x;}intMain () {intN,I,T,P,ANS1,ANS2,P1,P2; while(~scanf("%d\n", &n)) {p1=p2=0; for(i=0; i<n;i++) {scanf("%d%d", &t,&p);if(t>0) {r[p2].x=t;                R[p2].a=p;            p2++; }Else{l[p1].x=t;                L[p1].a=p;            p1++;        }} sort (L,L+P1,C2); Sort (R,R+P2,C1);intu1[1024x768],u2[1024x768];memset(U1,0,sizeof(U1));memset(U2,0,sizeof(U2)); for(ans1=0, i=0;; i++) {if(i%2==0)            {if(i/2&GT;=P1) Break; ans1+=l[i/2].A; }Else{if(i/2&GT;=P2) Break; ans1+=r[i/2].A; }        } for(ans2=0, i=0;; i++) {if(i%2==1)            {if(i/2&GT;=P1) Break; ans2+=l[i/2].A; }Else{if(i/2&GT;=P2) Break; ans2+=r[i/2].A; }        }printf("%d\n", Max (ANS1,ANS2)); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

CF 558A Lala Land and Apple Trees

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.