static int max_k_pairs_profits(List<Integer> A, int k) {
	  List<Integer> k_sum = new ArrayList<Integer>(k << 1);
	  fill(k_sum, k << 1, Integer.MIN_VALUE);
	  
	  for (int i = 0; i < A.size(); ++i) {
	    List<Integer> pre_k_sum = new ArrayList<Integer>(k_sum);
	    
	    for (int j = 0, sign = -1; j < k_sum.size() && j <= i; ++j, sign *= -1) {
	      int diff = sign * A.get(i) + (j == 0 ? 0 : pre_k_sum.get(j - 1));
	      k_sum.set(j, max(diff, pre_k_sum.get(j)));
	    }
	  }
	  
	  return k_sum.get(k_sum.size() - 1);  // returns the last selling profits as the answer.
	}