fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. const int mod=1e9+7;
  7.  
  8. int main() {
  9. int t, n, s;
  10. cin >> t;
  11. while (t--) {
  12. cin >> n;
  13. vector<long long> set(n);
  14. for (int i = 0; i < n; i++) {
  15. cin >> set[i];
  16. }
  17. sort(set.begin(), set.end());
  18. long long sum = 0;
  19. for (int i = 1; i < n; i++) {
  20. sum += (set[i] * ((1LL << i) - 1))%mod;
  21. }
  22. for (int i = 0; i < n - 1; i++) {
  23. sum -= (set[i] * ((1LL << (n - i - 1)) - 1))%mod;
  24. }
  25. cout << sum << endl;
  26. }
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5272KB
stdin
Set Difference  Add problem to Todo list
Problem code: SETDIFF  	
SUBMITMY SUBMISSIONSALL SUBMISSIONS
Read problems statements in Mandarin Chinese and Russian.

Churu is working as a data scientist in Coderpur. He works on a lot of data on the daily basis. One day, he found an interesting problem, which was very easy to solve for small data but was getting more complex with increasing number of data points. So, Churu needs your help in solving this problem.
Given a set S of N non-negative integers (Some integers might occur more than once in the set), find out the value of SETDIFF(S).
Mountain View
Where max(s) represents the maximum value in set s whereas min(s) represents the minimum value in the set s.
As value of SETDIFF(S) can be very large, print it modulo (109 + 7) .
Input

First line of input contains an integer T denoting number of test cases.
For each test case, first line will contain an integer N denoting number of elements in set S.
Next line contains N space separated integers denoting the set S.
Output

For each test case, print a single integer representing the answer of that test case.
Note

Two subsets will be called different if there exists an index i such that S[i] is occurs in one of the subset and not in another.
Constraints

Subtask #1: 20 points
1 ≤ T ≤ 5, 1 ≤ N ≤ 1000, 0 ≤ value in set ≤ 109
Subtask #2: 25 points
1 ≤ T ≤ 5, 1 ≤ N ≤ 105, 0 ≤ value in set ≤ 1000
Subtask #3: 55 points
1 ≤ T ≤ 5, 1 ≤ N ≤ 105, 0 ≤ value in set ≤ 109
Example

Input:
3
2
1 2
3
1 2 3
4
1 2 3 4
stdout
Standard output is empty