About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

রবিবার, ৩০ আগস্ট, ২০১৫

UVA:10954 - Add All

#include <bits/stdc++.h>
#define READ freopen ("input.txt","r",stdin)
#define nnn 20

using namespace std;

typedef long long ll;
typedef vector < int > vi;

int main()
{
    //READ;
    priority_queue<int>A;
    int n;
    while(scanf("%d",&n)==1&&n)
    {
        for(int i=0; i<n; i++)
        {
            int x;
            scanf("%d",&x);
            A.push(-x);
        }
        ll sum=0;
        while(A.size()>1)
        {
            int p=A.top();
            A.pop();
            int q=A.top();
            A.pop();
            sum+=(ll)(abs(p)+abs(q));
            A.push(-1*(abs(p)+abs(q)));
          //  cout<<A.top()<<endl;


        }
        cout<<sum<<endl;
        while(!A.empty()) A.pop();
    }



    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন