#include <bitset>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#define int long long
#define pb push_back
#define MOD 1000000007
#define NMAX 250001
#define nl '\n'
#define INF 1000000007
#define pii1 pair<int, pair<int,int>> (1,(1,2));
#define pii pair<int,int>
#define tpl tuple<int,int,int>
using namespace std;
ifstream fin("data.in");
ofstream fout("data.out");
/*
--------------------DEMONSTRATION---------------------
3-2
5-3
4-1
2-1
4-3
3-2
subtask 1:1<=n<=4, 1<=h<=9 ,1<=k<=4;
5*(5+1)/2=10;
1+2+3+4+5=15
------------------------END--------------------------
*/
int n,h,k;
int max_h;
vector<pii>v;
void subtask1()
{
map<int,int>mp;
for(int i=n;i>=1;--i)
{
int cnt=v[i].second;
bool used[cnt+1];
memset(used,false,sizeof(used));
for(int j=v[i].first;j>=1 && cnt;--j)
{
if(!mp[j])
{
used[j]=1;
cnt--;
mp[j]++;
}
}
if(cnt)
{
vector<int>aux;
for(auto [x,y]:mp)
{
if(used[x] || x>v[i].first)
continue;
aux.pb(x);
}
auto cmp=[&](int a,int b)
{
if(mp[a]==mp[b])
return a>b;
return mp[a]<mp[b];
};
sort(aux.begin(), aux.end(),cmp);
for(auto x:aux)
{
if(!cnt)
break;
cnt--;
mp[x]++;
}
}
}
int ans=0;
for(int i=1;i<=max_h;++i)
{
// cout<<mp[i]-1<<" ";
if(mp[i])
{
mp[i]--;
ans+=(mp[i]*(mp[i]+1))/2;
}
}
cout<<ans;
}
signed main() {
cin>>n;
v.resize(n+1);
for(int i=1;i<=n;++i)
{
cin>>h>>k;
v[i]={h,k};
max_h=max(max_h,h);
}
if(n<10)
{
subtask1();
return 0;
}
else
cout<<0;
return 0;
}
Compilation message
sails.cpp: In function 'void subtask1()':
sails.cpp:78:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
78 | for(auto [x,y]:mp)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
1884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |