My Blog List

Sunday, December 21, 2014

Topcoder SRM 641 250point


My answer is like this.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
public class BuyingTshirts {

 public int meet(int T, int[] Q, int[] P){
  int len = Q.length;
  int count = 0;
  
  int sum = 0;
  int sum2 = 0;
  for(int i=0; i<len; i++){
   sum += Q[i];
   sum2 += P[i];
   if(sum-T >= 0 || sum2 -T > 0){
    count++;
   }
   sum = sum - T;
   sum2 = sum2  - T ;
  }
  return count;
 }
}

No comments:

Post a Comment