Advertisement
erfanul007

Untitled

Jan 16th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int> pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define pb push_back
  14. #define pob pop_back
  15. #define mp make_pair
  16. #define ff first
  17. #define ss second
  18. #define loop1(i,n) for(int i=1; i<int(n); i++)
  19. #define loop(i,y) for(int i=0; i<int(y); i++)
  20. #define rloop(i,y) for(int i=int(y); i>0; i--)
  21. #define rloop1(i,y) for(int i=int(y)-1; i>=0; i--)
  22. #define read() freopen("input.txt", "r", stdin)
  23. #define write() freopen("output.txt", "w", stdout)
  24. #define cspf(i) printf("Case %d: \n", i)
  25. #define all(v) v.begin(),v.end()
  26. #define rall(v) v.rbegin(),v.rend()
  27. /// Constants
  28. #define eps 1e-9
  29. #define PI acos(-1.0) // 3.1415926535897932
  30.  
  31. int main()
  32. {
  33. ll n,m,x,sm=0,tm;
  34. cin>>n>>m;
  35. vll vt;
  36. loop(i,n){
  37. cin>>x;
  38. vt.pb(x);
  39. }
  40. sort(rall(vt));
  41. loop1(i,n){
  42. if(vt[i]<vt[i-1]){
  43. sm+=vt[i];
  44. continue;
  45. }
  46. if(vt[i]==vt[i-1] && vt[i]!=1){
  47. sm+=vt[i];
  48. vt[i]--;
  49. continue;
  50. }
  51. if(vt[i]>vt[i-1]){
  52. if(vt[i-1]>1){
  53. tm=vt[i]-vt[i-1];
  54. tm++;
  55. sm+=tm;
  56. vt[i]=vt[i]-tm;
  57. sm+=vt[i];
  58. continue;
  59. }
  60. else{
  61. sm=sm+(vt[i]-1);
  62. vt[i]=1;
  63. continue;
  64. }
  65. }
  66. }
  67. cout<<sm<<endl;
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement