Advertisement
Guest User

Untitled

a guest
Apr 29th, 2018
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. /*
  2. ID: hepic
  3. PROG: sabotage
  4. LANG: C++11
  5. */
  6. #include <bits/stdc++.h>
  7.  
  8. #define FOR(i, a, b) for(auto i=a; i<=b; ++i)
  9. #define REP(i, a, b) for(auto i=a; i<b; ++i)
  10. #define FORI(i, a, b) for(auto i=a; i!=b+1-2*(a>b); i+=1-2*(a>b))
  11. #define REPI(i, a, b) for(auto i=a-(a>b); i!=b-(a>b); i+=1-2*(a>b))
  12. #define ALL(v) v.begin(),v.end()
  13. #define mp(a, b) make_pair(a, b)
  14. #define pb(a) push_back(a)
  15. #define pf(a) push_front(a)
  16. #define eb(a, b) emplace_back(a, b)
  17. #define fir first
  18. #define sec second
  19. #define what_is(x) cout<<#x<<" is "<<x<<endl;
  20. #define type(x) typeid(x).name()
  21. #define ms(arr, val) memset(arr, val, sizeof(arr))
  22. #define min3(a,b,c) min(min(a,b),c)
  23. #define max3(a,b,c) max(max(a,b),c)
  24. #define PI acos(-1)
  25. #define open_read1 freopen("a.txt", "r", stdin)
  26. #define open_write1 freopen("b.xt", "w", stdout)
  27. #define open_read freopen("sort.in", "r", stdin)
  28. #define open_write freopen("sort.out", "w", stdout)
  29.  
  30. using namespace std;
  31.  
  32. typedef long long LL;
  33. typedef long double LD;
  34. typedef unsigned long long ULL;
  35. typedef pair<double, double> PDD;
  36. typedef pair<int, int> PII;
  37. typedef pair<int, PII> PIPII;
  38. typedef pair<PII, PII> PPIIPII;
  39. typedef pair<LL, LL> PLL;
  40. typedef pair<ULL, ULL> PUU;
  41. typedef pair<LL, PLL> PLPLL;
  42. typedef pair<PLL, PLL> PPLLPLL;
  43. typedef pair<int, LL> PIL;
  44. typedef pair<LL, int> PLI;
  45.  
  46.  
  47. template<typename T, typename T1>
  48. ostream& operator << (ostream &out, pair<T, T1> obj)
  49. {
  50. out << "(" << obj.first << ", " << obj.second << ")";
  51. return out;
  52. }
  53.  
  54.  
  55. template<typename T, typename T1>
  56. ostream& operator << (ostream &out, map<T, T1> cont)
  57. {
  58. typename map<T, T1>::const_iterator itr = cont.begin();
  59. typename map<T, T1>::const_iterator ends = cont.end();
  60.  
  61. for(; itr!=ends; ++itr)
  62. out<<*itr<<" ";
  63. out<<endl;
  64.  
  65. return out;
  66. }
  67.  
  68.  
  69. template<typename T>
  70. ostream& operator << (ostream &out, set<T> cont)
  71. {
  72. typename set<T>::const_iterator itr = cont.begin();
  73. typename set<T>::const_iterator ends = cont.end();
  74.  
  75. for(; itr!=ends; ++itr)
  76. out<<*itr<<" ";
  77. out<<endl;
  78.  
  79. return out;
  80. }
  81.  
  82.  
  83. template<typename T>
  84. ostream& operator << (ostream &out, multiset<T> cont)
  85. {
  86. typename multiset<T>::const_iterator itr = cont.begin();
  87. typename multiset<T>::const_iterator ends = cont.end();
  88.  
  89. for(; itr!=ends; ++itr)
  90. out<<*itr<<" ";
  91. out<<endl;
  92.  
  93. return out;
  94. }
  95.  
  96.  
  97. template<typename T, template<typename ELEM, typename ALLOC=allocator<ELEM>> class CONT>
  98. ostream& operator << (ostream &out, CONT<T> cont)
  99. {
  100. typename CONT<T>::const_iterator itr = cont.begin();
  101. typename CONT<T>::const_iterator ends = cont.end();
  102.  
  103. for(; itr!=ends; ++itr)
  104. out<<*itr<<" ";
  105. out<<endl;
  106.  
  107. return out;
  108. }
  109.  
  110.  
  111. template<typename T, unsigned int N, typename CTy, typename CTr>
  112. typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
  113. operator << (basic_ostream<CTy, CTr> &out, const T (&arr)[N])
  114. {
  115. REP(i, 0, N)
  116. out<<arr[i]<<" ";
  117. out<<endl;
  118.  
  119. return out;
  120. }
  121.  
  122.  
  123. template<typename T>
  124. T gcd(T a, T b)
  125. {
  126. T min_v = min(a, b);
  127. T max_v = max(a, b);
  128.  
  129. while(min_v)
  130. {
  131. T temp = max_v % min_v;
  132. max_v = min_v;
  133. min_v = temp;
  134. }
  135.  
  136. return max_v;
  137. }
  138.  
  139.  
  140. template<typename T>
  141. T lcm(T a, T b)
  142. {
  143. return (a*b) / gcd(a, b);
  144. }
  145.  
  146.  
  147. template<typename T>
  148. T fast_exp_pow(T base, T exp, T mod)
  149. {
  150. T res = 1;
  151.  
  152. while(exp)
  153. {
  154. if(exp&1)
  155. {
  156. res *= base;
  157. res %= mod;
  158. }
  159.  
  160. exp >>= 1;
  161. base *= base;
  162. base %= mod;
  163.  
  164. }
  165.  
  166. return res % mod;
  167. }
  168.  
  169. /*#################################################################################################################
  170. #################################################################################################################
  171. ################################################################################################################
  172. #################################################################################################################*/
  173.  
  174. #define SIZE 300
  175.  
  176. int T, N, L, answer;
  177. int votes[SIZE];
  178. bool counted[SIZE];
  179. vector<int> goodNums;
  180. priority_queue<PII, vector<PII>, greater<PII>> changeNums;
  181.  
  182.  
  183. void initialize() {
  184. while (!changeNums.empty()) {
  185. changeNums.pop();
  186. }
  187.  
  188. goodNums.clear();
  189. ms(counted, false);
  190. answer = 0;
  191. }
  192.  
  193. int toRound(int value) {
  194. if ((value * 1000) % N == 0) {
  195. return value * 100 / N;
  196. }
  197.  
  198. if ((value * 1000 / N) % 10 >= 5) {
  199. return value * 100 / N + 1;
  200. }
  201.  
  202. return value * 100 / N;
  203. }
  204.  
  205.  
  206. int main() {
  207. scanf("%d", &T);
  208.  
  209. FOR (t, 1, T) {
  210. initialize();
  211. scanf("%d%d", &N, &L);
  212.  
  213. FOR (i, 1, N) {
  214. if ((i * 1000 / N) % 10 >= 5) {
  215. goodNums.pb(i);
  216. }
  217. }
  218.  
  219. //cout << goodNums << endl;
  220. int rest = N;
  221.  
  222. REP (i, 0, L) {
  223. scanf("%d", votes + i);
  224. auto itr = lower_bound(ALL(goodNums), votes[i]);
  225.  
  226. if (*itr == votes[i]) {
  227. answer += toRound(votes[i]);
  228. counted[i] = true;
  229. } else {
  230. changeNums.push(mp(*itr - votes[i], i));
  231. }
  232.  
  233. rest -= votes[i];
  234. }
  235.  
  236. FOR (i, 1, rest) {
  237. changeNums.push(mp(*goodNums.begin(), -1));
  238. }
  239.  
  240. while(!changeNums.empty() && rest) {
  241. PII elem = changeNums.top();
  242. changeNums.pop();
  243.  
  244. int temp = min(rest, elem.fir);
  245.  
  246. if (elem.sec == -1) {
  247. answer += toRound(temp);
  248. } else {
  249. votes[elem.sec] += temp;
  250. }
  251.  
  252. rest -= temp;
  253. }
  254.  
  255. REP (i, 0, L) {
  256. if (!counted[i]) {
  257. answer += toRound(votes[i]);
  258. }
  259. }
  260.  
  261. printf("Case #%d: %d\n", t, answer);
  262. }
  263.  
  264. return 0;
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement