/*****from dust I have come, dust I will be*****/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define double long double
#define forn(i,n) for(int i=0;i<n;i++)
int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int ceil_div(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}
const int MOD = 1000000007;
//const int MOD = 998244353;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
/*
int k = A.order_of_key(p[i].second);
A.erase(A.find_by_order(k));
erase element from pbds multiset
*/
//ako hocemo da broj sk, predstavimo
//kao zbir k cifara, a da te cifre budu
//najvece moguce
void sumk(vector<int>&ans, int sk, int k){
for(int i = 0; i < k; i++) {
ans[i] += sk / k;
if (sk % k != 0) ans[i]++, sk--;
}
}
int formula(int n){
return (n * (n + 1) / 2);
}
void solve(){
int n; cin >> n;
vector<int>a(n);
int sum = 0;
forn(i,n){
int s;
cin >> a[i]>> s;
sum += s;
}
sort(a.begin(), a.end());
int ukupno = n;
vector<int>b;
int p1 = 0;
for (int i=1;i<=a.back();i++){
while (p1 < n && i > a[p1]){
p1++;
ukupno--;
}
b.push_back(ukupno);
}
int prev = 0;
vector<int>tmp((int)b.size() + 1);
for (int i=(int)b.size()-1;i>=0;i--){
int br = i + 1;
int x = (b[i] - prev) * br;
if (x <= sum){
tmp[0] += (b[i] - prev);
tmp[(int)b.size()] -= (b[i] - prev);
sum -= x;
}
else{
for (int i=1;i<(int)b.size();i++) tmp[i] += tmp[i-1];
sumk(tmp, sum, br);
// for (int i=0;i<(int)b.size();i++) cout <<tmp[i]<<' ';
// cout <<'\n';
break;
}
prev = b[i];
}
int ans = 0;
for (int i=0;i<(int)b.size();i++) ans += formula(tmp[i]-1);
cout <<ans<<'\n';
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1; //cin >>t;
for (int i=1;i<=t;i++){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
2520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
3592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
3800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
4048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |