[NOIP 2004] T3 合並果子
阿新 • • 發佈:2017-12-08
digi tchar 完全 char zoj getchar for vector priority
居然和BZOJ 1724完全一樣o(╯□╰)o
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; priority_queue<int,vector<int>,greater<int> > q; inline int read() { char ch; int num,f=0; while(!isdigit(ch=getchar())) f|=(num==‘-‘); num=ch-‘0‘; while(isdigit(ch=getchar())) num=num*10+ch-‘0‘; return f?-num:num; } int main() { n=read(); for(int i=1;i<=n;i++) { int x=read(); q.push(x); } if(n==1){cout << q.top();return 0;} ll res=0; while(q.size()>1) { int x=q.top();q.pop(); int y=q.top();q.pop(); res+=(x+y); q.push(x+y); } cout << res; return 0; }
[NOIP 2004] T3 合並果子