CF1646B Solution 2022-07-29 作者 Lotuses 742 字 本文最后编辑于 2年 前,其中的内容可能需要更新。 1. Solution Solution 贪心。想要 和大于 和,而且 数量还得更少,那么只能让 中的元素远远大于 中元素。 那么排一遍升序,从左到右选,左边选 个数当做 ,右边选择 个数当做 ,如果扫完全序列都不能满足,那必然是 nO 了。 单次 ,均摊总时间复杂度 。 1234567891011121314151617181920212223242526272829#include<bits/stdc++.h>using namespace std;long long a[1000001];int main(){ int t; cin>>t; while(t--) { int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); long long s1=a[1]+a[2],s2=a[n]; int i=2,j=n; bool flag=0; while(i+1<j) { if(s1<s2) {flag=1;break;} i++;j--; s1+=a[i];s2+=a[j]; } if(s1<s2) flag=1; if(flag) cout<<"YES\n"; else cout<<"NO\n"; } return 0;} 复制 本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可 < 上一篇 下一篇 > Please enable JavaScript to view the comments powered by Gitalk.