fork download
  1. /* � Ashiq Uddin Pranto
  2.   Department of Computer Science and Engineering
  3.   BATCH 27
  4.   University Of Rajshahi,Bangladesh
  5. */
  6. #include<bits/stdc++.h>
  7.  
  8. #define ll long long
  9. #define ld long double
  10. #define FOR(x,y) for(ll i=x;i<=y;i++)
  11. #define pb(x) push_back(x)
  12. #define mp make_pair
  13. #define pii pair<int,int>
  14. #define pll pair<ll,ll>
  15. #define vii vector<int>
  16. #define vll vector<ll>
  17. #define matrix(x) vector<vector<x>>
  18. #define vss vector<string>
  19. #define PI (2*acos(0.0))
  20. #define sqr(x) ((x)*(x))
  21. #define sf(a) scanf("%d",&a)
  22. #define sfl(a) scanf("%lld",&a)
  23. #define sff(a,b) scanf("%d %d",&a,&b)
  24. #define sffl(a,b) scanf("%lld %lld",&a,&b)
  25. #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
  26. #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
  27. #define ms(a,b) memset(a, b, sizeof(a))
  28. #define ff first
  29. #define ss second
  30. #define lcm(a, b) ((a)*((b)/__gcd(a,b)))
  31. #define all(a) a.begin(),a.end()
  32. #define readfile freopen("input.txt","r",stdin);
  33. #define writefile freopen("output.txt","w",stdout);
  34. #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
  35. #define gap " "
  36. #define mx 104
  37. #define inf (ll)1e9
  38. #define WHITE 1
  39. #define GRAY 2
  40. #define BLACK 3
  41. #define EMPTY_VALUE -1
  42. #define mod 1000000007
  43. #define MOD(a,b) (a%b + b)%b
  44.  
  45. using namespace std;
  46.  
  47. void __print(int x) {cerr << x;}
  48. void __print(long x) {cerr << x;}
  49. void __print(long long x) {cerr << x;}
  50. void __print(unsigned x) {cerr << x;}
  51. void __print(unsigned long x) {cerr << x;}
  52. void __print(unsigned long long x) {cerr << x;}
  53. void __print(float x) {cerr << x;}
  54. void __print(double x) {cerr << x;}
  55. void __print(long double x) {cerr << x;}
  56. void __print(char x) {cerr << '\'' << x << '\'';}
  57. void __print(const char *x) {cerr << '\"' << x << '\"';}
  58. void __print(const string &x) {cerr << '\"' << x << '\"';}
  59. void __print(bool x) {cerr << (x ? "true" : "false");}
  60.  
  61. template<typename T, typename V>
  62. void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  63. template<typename T>
  64. void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  65. void _print() {cerr << "]\n";}
  66. template <typename T, typename... V>
  67. void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  68. #ifndef ONLINE_JUDGE
  69. #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
  70. #else
  71. #define debug(x...)
  72. #endif
  73.  
  74. void eff()
  75. {
  76. ll n,k;
  77. sffl(n,k);
  78. vll a(n);
  79. map<ll,ll>cnt;
  80. for(ll i=0;i<n;i++)
  81. {
  82. sfl(a[i]);
  83. cnt[a[i]]++;
  84. }
  85. // debug(cnt);
  86. ll boxmax;
  87. auto x = cnt.begin();
  88. if(x->first==0)
  89. {
  90. boxmax = min(k,x->second);
  91. }
  92. else
  93. {
  94. printf("0\n");
  95. return;
  96. }
  97. ll i=0;
  98. ll ans = 0;
  99. ll lastfirst = 0;
  100. for(auto x: cnt)
  101. {
  102. if(abs(lastfirst-x.first)>=2)
  103. {
  104. ans+=i*(boxmax);
  105. cout<<ans<<endl;
  106. return;
  107. }
  108. if(x.second <boxmax)
  109. {
  110. ans+=i*(boxmax-1);
  111. // ans+=i;
  112. boxmax = x.second;
  113. }
  114. lastfirst = x.first;
  115. i++;
  116. }
  117. ans+=i*(boxmax);
  118. cout<<ans<<endl;
  119.  
  120. }
  121.  
  122. int main()
  123. {
  124. // fastio
  125. // ll test ;
  126. // sfl(test);
  127. // for(ll i=0;i<test;i++)
  128. // {
  129. // printf("Case %lld: ",i+1);
  130. eff();
  131. // }
  132. // cout<<check(81);
  133. return 0;
  134. }
  135.  
Success #stdin #stdout 0.01s 4916KB
stdin
Standard input is empty
stdout
2