Submission #1004675

#TimeUsernameProblemLanguageResultExecution timeMemory
1004675Trisanu_DasJobs (BOI24_jobs)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<long long> x; vector<vector<int> > c; vector<pair<long long, long long> > res; long long dfs(int a) { long long sum = x[a]; for(int i = 0; i < c[a].size(); i++) sum += dfs(c[a][i]); return max(sum, 0ll); } void dfs2(int a, long long pr, long long mp, long long lo) { long long nex = pr + x[a]; if(nex > mp) res.push_back({lo - mp, nex - mp}); for(int i = 0; i < c[a].size(); i++) dfs2(c[a][i], nex, max(mp, nex), min(lo, nex)); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, a; long long s; cin >> n >> s; x.resize(n + 1); c.resize(n + 1); x[0] = 0ll; for(int i = 1; i <= n; i++){ cin >> x[i] >> a; c[a].push_back(i); } if(s == 1e18) cout << dfs(0) << '\n'; else { ll ans = 0; for(int i = 0; i < c[0].size(); i++) dfs2(c[0][i], 0ll, 0ll, 0ll); sort(res.begin(), res.end(), greater<pair<long long, long long> >()); for(int i = 0; i < res.size(); i++){ if(res[i].fir + s < 0) break; s += res[i].sec; ans += res[i].sec; } cout << ans << '\n'; } }

Compilation message (stderr)

Main.cpp: In function 'long long int dfs(int)':
Main.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0; i < c[a].size(); i++) sum += dfs(c[a][i]);
      |                 ~~^~~~~~~~~~~~~
Main.cpp: In function 'void dfs2(int, long long int, long long int, long long int)':
Main.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i = 0; i < c[a].size(); i++) dfs2(c[a][i], nex, max(mp, nex), min(lo, nex));
      |                 ~~^~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:33:3: error: 'll' was not declared in this scope
   33 |   ll ans = 0;
      |   ^~
Main.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 0; i < c[0].size(); i++) dfs2(c[0][i], 0ll, 0ll, 0ll);
      |                  ~~^~~~~~~~~~~~~
Main.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for(int i = 0; i < res.size(); i++){
      |                  ~~^~~~~~~~~~~~
Main.cpp:37:14: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'fir'; did you mean 'first'?
   37 |    if(res[i].fir + s < 0) break;
      |              ^~~
      |              first
Main.cpp:38:16: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'sec'
   38 |    s += res[i].sec;
      |                ^~~
Main.cpp:39:4: error: 'ans' was not declared in this scope; did you mean 'abs'?
   39 |    ans += res[i].sec;
      |    ^~~
      |    abs
Main.cpp:39:18: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'sec'
   39 |    ans += res[i].sec;
      |                  ^~~
Main.cpp:41:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   41 |   cout << ans << '\n';
      |           ^~~
      |           abs