Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long lli;
- const int T = 1e5;
- int chicken[T + 10];
- int main(){
- int nChicken;
- int mx = 0;
- scanf("%d", &nChicken);
- for(int i = 1; i <= nChicken; ++i){
- int x;
- scanf("%d", &x);
- ++chicken[x];
- mx = max(mx, x);
- }
- int tr;
- scanf("%d", &tr);
- lli cnt = 0;
- for(int i = 0; i <= tr >> 1; ++i){
- if(tr - i > mx){
- continue;
- }
- if(i + i == tr){
- cnt += (lli)chicken[i] * (chicken[i] - 1) / 2;
- } else {
- cnt += (lli)chicken[i] * chicken[tr - i];
- }
- }
- cout << cnt;
- return 0;
- }
Add Comment
Please, Sign In to add comment