#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;
long long licz(int n)
{
if (n - 1 == 0) return 1;
return ((licz(n - 1) * n) / 2) % 1000000007;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t, a;
int* tab = new int[5005]();
long long* pom = new long long[5005]();
queue<long long > ile;
long long wynik = 0;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> a;
tab[a]++;
}
long long s = 0;
for (int i = 1; i < 5005; i++)
pom[i] = 1;
for (int i = 1; i <= 5000; i++)
{
int n = tab[i];
int k = n;
s += n * i;
if (s > 5000) s = 5001;
long long sum = 0, b;
if (s < i) break;
// pom[i] *= n;
ile.push(n);
sum += n;
while ((n - 1) > 0)
{
b = (((n - 1) * n) / 2) % 10000000007;
sum = (sum + b) % 10000000007;
ile.push(b);
n--;
}
pom[i] *= sum;
int d = i ;
long long gora = sum;
if (ile.size() > 1)
{
for(int o=0; o<ile.size(); o++)
//while (!ile.empty())
{
for (int z = d+1; z <= d + i; z++)
{
pom[z] =max(gora,pom[z]);
pom[z] %= 10000000007;
}
d += (i - 1);
gora -= ile.front();
ile.pop();
}
ile.pop();
}
else ile.pop();
/* for (int i = 1; i < s; i++)
cout<< pom[i]<<" " ;
cout << endl;*/
}
for (int i = 1; i <= s; i++)
{
if (tab[i] != 0) wynik = (wynik + pom[i]) % 10000000007;
//cout << tab[i] << " " << pom[i] << endl;
}
cout << wynik;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | #include <iostream> #include <string> #include <vector> #include <queue> #include <algorithm> #include <cmath> #include <climits> using namespace std; long long licz(int n) { if (n - 1 == 0) return 1; return ((licz(n - 1) * n) / 2) % 1000000007; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t, a; int* tab = new int[5005](); long long* pom = new long long[5005](); queue<long long > ile; long long wynik = 0; cin >> t; for (int i = 0; i < t; i++) { cin >> a; tab[a]++; } long long s = 0; for (int i = 1; i < 5005; i++) pom[i] = 1; for (int i = 1; i <= 5000; i++) { int n = tab[i]; int k = n; s += n * i; if (s > 5000) s = 5001; long long sum = 0, b; if (s < i) break; // pom[i] *= n; ile.push(n); sum += n; while ((n - 1) > 0) { b = (((n - 1) * n) / 2) % 10000000007; sum = (sum + b) % 10000000007; ile.push(b); n--; } pom[i] *= sum; int d = i ; long long gora = sum; if (ile.size() > 1) { for(int o=0; o<ile.size(); o++) //while (!ile.empty()) { for (int z = d+1; z <= d + i; z++) { pom[z] =max(gora,pom[z]); pom[z] %= 10000000007; } d += (i - 1); gora -= ile.front(); ile.pop(); } ile.pop(); } else ile.pop(); /* for (int i = 1; i < s; i++) cout<< pom[i]<<" " ; cout << endl;*/ } for (int i = 1; i <= s; i++) { if (tab[i] != 0) wynik = (wynik + pom[i]) % 10000000007; //cout << tab[i] << " " << pom[i] << endl; } cout << wynik; return 0; } |
English