jainbot27

timeismoney

Jul 25th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #pragma GCC target("sse4")
  3. #include <bits/stdc++.h>
  4. #define f first
  5. #define s second
  6. #define pb push_back
  7. #define mp make_pair
  8. #define ts to_string
  9. #define ub upper_bound
  10. #define lb lower_bound
  11. const char nl = '\n';
  12. using namespace std;
  13. using ll = long long;
  14. using vi = vector<int>;
  15. using vl = vector<ll>;
  16. using pii = pair<int, int>;
  17. using pll = pair<ll, ll>;
  18. using str = string;
  19. //The following debugging code was taken from Benjamin Qi's template :)
  20. str ts(char c) { return str(1,c); }
  21. str ts(bool b) { return b ? "true" : "false"; }
  22. str ts(const char* s) { return (str)s; }
  23. str ts(str s) { return s; }
  24. template<class A> str ts(complex<A> c) {
  25.     stringstream ss; ss << c; return ss.str(); }
  26. str ts(vector<bool> v) {
  27.     str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
  28.     res += "}"; return res; }
  29. template<size_t SZ> str ts(bitset<SZ> b) {
  30.     str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
  31.     return res; }
  32. template<class A, class B> str ts(pair<A,B> p);
  33. template<class T> str ts(T v) {
  34.     bool fst = 1; str res = "{";
  35.     for (const auto& x: v) {
  36.         if (!fst) res += ", ";
  37.         fst = 0; res += ts(x);
  38.     }
  39.     res += "}"; return res;
  40. }
  41. template<class A, class B> str ts(pair<A,B> p) {
  42.     return "("+ts(p.f)+", "+ts(p.s)+")"; }
  43. void DBG() { cerr << "]" << endl; }
  44. template<class H, class... T> void DBG(H h, T... t) {
  45.     cerr << ts(h); if (sizeof...(t)) cerr << ", ";
  46.     DBG(t...); }
  47.  
  48. #ifdef LOCAL
  49. #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
  50. #else
  51. #define dbg(...) 0
  52. #endif
  53. //CODE STARTS HERE-----------------------------------------------------------------------------------------//
  54. const int N = 1010;
  55. int n, m, c;
  56. int dp[N][N], cost[N];
  57. vector<pii> edges;
  58. signed main(){
  59.     cin.tie(nullptr);
  60.     ios_base::sync_with_stdio(false);
  61.     freopen("time.in", "r", stdin);
  62.     freopen("time.out", "w", stdout);
  63.     cin >> n >> m >> c;
  64.     for(int i =0 ; i < n; i++)
  65.         cin >> cost[i];
  66.     for(int i =0; i < m; i++){
  67.         int a, b;
  68.         cin >> a >> b;
  69.         edges.pb({a-1, b-1});
  70.     }
  71.     for(int i=0; i < 1001; i++) for(int j = 0; j < n; j++) dp[i][j] = -1e9;
  72.     dp[0][0] = 0;
  73.     int ans = 0;
  74.     for(int t = 1; t <= 1000; t++){
  75.         for(pii e : edges){
  76.             dp[t][e.s] = max(dp[t][e.s], dp[t-1][e.f] + cost[e.f]);
  77.         }
  78.         ans = max(ans, dp[t][0] - c * t * t);
  79.     }
  80.     cout << ans << nl;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment