Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin ("time.in");
  5. ofstream fout ("time.out");
  6. int n, m, c, x, y, a[1005][1005], val[1005], maxx;
  7. vector <int> v[1005];
  8.  
  9. int main()
  10. {
  11. fin >> n >> m >> c;
  12. for(int i=1;i<=n;i++)
  13. fin >> val[i];
  14.  
  15. for(int i=1;i<=m;i++)
  16. {
  17. fin >> x >> y;
  18. v[x].push_back(y);
  19. }
  20.  
  21. for(int i=0;i<=n;i++)
  22. a[0][i]=-1;
  23. a[0][1]=0;
  24.  
  25. for(int i=0;i<=1000;i++)
  26. {
  27. for(int j=1;j<=n;j++)
  28. a[i+1][j]=-1;
  29.  
  30. for(int j=1;j<=n;j++)
  31. if(a[i][j]!=-1)
  32. for(auto it:v[j])
  33. a[i+1][it]=max(a[i+1][it], a[i][j]+val[it]);
  34. }
  35.  
  36. for(int i=0;i<=1000;i++)
  37. maxx=max(maxx, a[i][1]-i*i*c);
  38. fout << maxx;
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement