Promi_38

All pair product sum

Jan 9th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. /* All pair product sum
  2. Sample Input 0
  3.  
  4. 3 2
  5. 1 2 3
  6. 4 5
  7. Sample Output 0
  8.  
  9. 54 */
  10.  
  11. #include<stdio.h>
  12.  
  13. int main()
  14. {
  15.     int n, m;
  16.     scanf("%d %d", &n, &m);
  17.    
  18.     int i, j, a[n], b[m];
  19.     for(i = 0; i < n; i++) scanf("%d", &a[i]);
  20.     for(j = 0; j < m; j++) scanf("%d", &b[j]);
  21.    
  22.     long long s = 0, ans = 0;
  23.     for(i = 0; i < n; i++)
  24.     {
  25.         s += a[i];
  26.     }
  27.     //printf("%lld\n", s);
  28.     for(j = 0; j < m; j++)
  29.     {
  30.         ans += s * b[j];
  31.     }
  32.     printf("%lld\n", ans);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment