#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX = 1e5+1;
int nbAHauteur[MAX];
int nbPeutSurHauteur[MAX];
signed main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int nbPoteaux;
cin >> nbPoteaux;
int nbRestants(0);
for (int iPoteau = 0; iPoteau < nbPoteaux; ++iPoteau)
{
int hauteur, aMettre;
cin >> hauteur >> aMettre;
nbAHauteur[hauteur]++;
nbRestants += aMettre;
nbPeutSurHauteur[hauteur] += aMettre;
}
int sol(0);
int nbPoteauxDispo = 0;
int nbDrapeauxDispo = 0;
for (int iHauteur(MAX-1); iHauteur; --iHauteur)
{
nbPoteauxDispo += nbAHauteur[iHauteur];
nbDrapeauxDispo += nbPeutSurHauteur[iHauteur];
int moy = (nbRestants + iHauteur - 1) / iHauteur;
int placeEtage = min({moy, nbPoteauxDispo, nbDrapeauxDispo});
nbDrapeauxDispo -= placeEtage;
nbRestants -= placeEtage;
sol += placeEtage * (placeEtage - 1) / 2;
}
assert(!nbRestants);
cout << sol << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1188 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
1900 KB |
Output is correct |
2 |
Correct |
17 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
1772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |