Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<algorithm>
  2. using namespace std;
  3. int main(){
  4. long long int K,N,i,j=0,k,total=0,tempTotal=0,temp;
  5. cin>>N>>K;
  6. long long arr[N];
  7. for(i=0;(i+j)<N;){
  8. cin>>arr[i];
  9. if(arr[i]<K){
  10. i++;
  11. sort(arr,arr+i);
  12. continue;
  13. }
  14. j++;
  15. }
  16. N=i;
  17.  
  18. for(i=0;i<N;i++){
  19. if(i==0||(arr[i]!=arr[i-1])){
  20. tempTotal=0;
  21. char flag=1;
  22. for(j=i+1;j<N&&flag;j++){
  23. flag=0;
  24. if(arr[i]+arr[j]<K){
  25. tempTotal++;
  26. flag=1;
  27. }
  28. }
  29. }
  30. else tempTotal-=(2*arr[i-1])<K;
  31. total+=tempTotal;
  32. }
  33.  
  34. cout<<total;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement