fork download
  1. /*
  2. Div-2 #308
  3. ID: ravi_rk
  4. PROG: Marking scheme
  5. LANG: C++11
  6. */
  7.  
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <cstdlib>
  11. #include <cstdio>
  12. #include <cmath>
  13. #include <string>
  14. #include <vector>
  15. #include <algorithm>
  16.  
  17. #define DEBUG 0
  18.  
  19. using namespace std;
  20.  
  21. template<class T> T power(T N,T P){ return (P==0)? 1: N*power(N,P-1); }
  22.  
  23. int main() {
  24.  
  25. std::ios_base::sync_with_stdio(false);
  26. cout << std::fixed;
  27. cout << std::setprecision(6);
  28.  
  29. int t, n, k, marks[50], up, low;
  30. double sum;
  31. long long int fav[1000];
  32.  
  33. cin >> t;
  34.  
  35. for (int i = 0; i < t; i++) {
  36. cin >> n;
  37. for(int j = 0; j < n; j++)
  38. cin >> fav[j];
  39. cin >> k;
  40. marks[0] = 0;
  41. for(int j = 1; j <= k; j++)
  42. cin >> marks[j];
  43. // sort(fav, fav + n);
  44. if(DEBUG) {
  45. for(int j = 0; j < n; j++)
  46. cout << fav[j] << ", ";
  47. cout << endl;
  48. }
  49. sort(marks, marks + k + 1);
  50. if(DEBUG) {
  51. for(int j = 0; j <= k; j++)
  52. cout << marks[j] << ", ";
  53. cout << endl;
  54. }
  55. int j = 0, l = 0, tmp;
  56. sum = 0;
  57. while(j < n && l <= k) {
  58. low = j;
  59. while(fav[j] == fav[j+1])
  60. j++;
  61. up = j+1;
  62. if(DEBUG)
  63. cout << "Up: " << up << ", Low: " << low << endl;
  64. sum += marks[l];
  65. if(DEBUG)
  66. cout << "Sum: " << sum << endl;
  67. if(up - low == 1 && fav[up] > fav[low]) {
  68. tmp = l;
  69. while(marks[l + 1] <= 2*marks[l])
  70. l++;
  71. if(tmp == l)
  72. l++;
  73. } else if(up - low > 1 && fav[up] > fav[up - 1]){
  74. l = 1;
  75. } else {
  76. l = 0;
  77. }
  78. j = up;
  79. if(DEBUG)
  80. cout << "J: " << j << ", L: " << l << endl;
  81. }
  82. cout << (double)sum/n << endl;
  83. }
  84. return 0;
  85. }
Success #stdin #stdout 0s 3236KB
stdin
Standard input is empty
stdout
Standard output is empty