Submission #476941

#TimeUsernameProblemLanguageResultExecution timeMemory
476941keta_tsimakuridzeWorst Reporter 4 (JOI21_worst_reporter4)C++14
0 / 100
16 ms14924 KiB
#include<bits/stdc++.h> #define f first #define s second #define int long long #define pii pair<int,int> using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; // ! int t,a[N],c[N],n; multiset<pii> s[N]; vector <int> V[N]; void dfs(int u) { for(int i = 0; i < V[u].size(); i++) { dfs(V[u][i]); int x = V[u][i]; if(s[u].size() < s[x].size()) swap(s[u],s[x]); while(s[x].size()) { pii y = *s[x].begin(); s[x].erase(s[x].find(y)); s[u].insert(y); } } // int saved = c[u]; while(s[u].upper_bound({a[u] + 1,-1}) != s[u].begin()){ pii x = *--s[u].upper_bound({a[u] + 1 ,-1}); s[u].erase(s[u].find(x)); if(x.s <= c[u]) { c[u] -= x.s; } else { s[u].insert({x.f,x.s - c[u]}); break; } } s[u].insert({a[u], saved}); } main(){ cin >> n; int sum = 0; for(int i = 1; i <= n; i++) { int p; cin >> p >> a[i] >> c[i]; sum += c[i]; if(i == 1) { if(p != 1) return 0; continue; } if(p >= i) return 0; V[p].push_back(i); } dfs(1); int ans = 0; for(multiset <pii> :: iterator it = s[1].begin(); it != s[1].end(); it++) { ans += (*it).s; } cout << sum - ans; }

Compilation message (stderr)

worst_reporter2.cpp: In function 'void dfs(long long int)':
worst_reporter2.cpp:12:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for(int i = 0; i < V[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
worst_reporter2.cpp: At global scope:
worst_reporter2.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...