2019-05-18 02:05:30 C++

C++

Copy Copied! Full
#include <bits/stdc++.h> using namespace std; vector<long long> a; int main(void){ int N; cin >> N; long long ans = 0; for(int i=0;i<N;i++){ long long b; cin >> b; a.push_back(abs(b)); } sort(a.begin(),a.end()); int left = 0; int right = 0; while(left!=N){ if(left==right){ right++; if(right==N)break; } if(abs(a[left]-a[right])<=a[left]){ if(right==(N-1)){ ans += right - left; left++; }else{ right++; } }else{ left++; ans += right - left; } } cout << ans << endl; }
RECOMMEND