Submission #19426526


Source Code Expand

Copy
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

bool compare ( const pair<int,int> &p1, const pair<int,int> &p2 ){
    return p1.sd < p2.sd;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    rep(i,0,a.size()){
        cin>>a[i];
    }
    vector<pair<int,int>> p(m);
    rep(i,0,p.size()){  
        int x,y;
        cin>>x>>y;
        p[i] = {x,y};
    }
    vector<int> dp(n,-2e9);
    sort(all(p),compare);
    // rep(i,0,p.size()){
    //     out2(p[i].ft,p[i].sd);
    // }
    int j = 0;
    rep(i,1,a.size()){
        while( p[j].sd == i+1 ){
            dp[i] = max(dp[p[j].ft - 1] + a[i] - a[p[j].ft - 1], max(dp[i],a[i] - a[p[j].ft - 1]));
            j++;
        } 
    }
    // rep(i,0,dp.size()){
    //     out1(dp[i]);
    // }
    cout<<*max_element(all(dp))<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

Submission Info

Submission Time
Task E - Peddler
User nissa_1900
Language C++ (GCC 9.2.1)
Score 0
Code Size 2095 Byte
Status WA
Exec Time 79 ms
Memory 9512 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:19:33: 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]
   19 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
   56 |     rep(i,0,a.size()){
      |         ~~~~~~~~~~~~             
./Main.cpp:56:5: note: in expansion of macro ‘rep’
   56 |     rep(i,0,a.size()){
      |     ^~~
./Main.cpp:19:33: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   19 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
   60 |     rep(i,0,p.size()){
      |         ~~~~~~~~~~~~             
./Main.cpp:60:5: note: in expansion of macro ‘rep’
   60 |     rep(i,0,p.size()){
      |     ^~~
./Main.cpp:19:33: 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]
   19 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
   71 |     rep(i,1,a.size()){
      |         ~~~~~~~~~~~~             
./Main.cpp:71:5: note: in expansion of macro ‘rep’
   71 |     rep(i,1,a.size()){
      |     ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 48
WA × 1
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All extreme_00.txt, extreme_01.txt, extreme_02.txt, extreme_03.txt, handmade_00.txt, handmade_01.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_dense_00.txt, random_dense_01.txt, random_dense_02.txt, random_dense_03.txt, random_dense_04.txt, random_dense_05.txt, random_dense_06.txt, random_dense_07.txt, random_dense_08.txt, random_dense_09.txt, random_small_00.txt, random_small_01.txt, random_small_02.txt, random_small_03.txt, random_small_04.txt, random_small_05.txt, random_small_06.txt, random_small_07.txt, random_small_08.txt, random_small_09.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
extreme_00.txt AC 79 ms 9448 KB
extreme_01.txt AC 76 ms 9512 KB
extreme_02.txt AC 63 ms 9452 KB
extreme_03.txt WA 32 ms 6332 KB
handmade_00.txt AC 3 ms 3560 KB
handmade_01.txt AC 2 ms 3496 KB
random_00.txt AC 51 ms 7404 KB
random_01.txt AC 66 ms 7892 KB
random_02.txt AC 40 ms 5956 KB
random_03.txt AC 29 ms 5288 KB
random_04.txt AC 36 ms 5576 KB
random_05.txt AC 23 ms 5760 KB
random_06.txt AC 14 ms 3948 KB
random_07.txt AC 40 ms 6304 KB
random_08.txt AC 62 ms 6728 KB
random_09.txt AC 42 ms 6796 KB
random_10.txt AC 29 ms 4720 KB
random_11.txt AC 62 ms 7788 KB
random_12.txt AC 36 ms 5832 KB
random_13.txt AC 53 ms 7940 KB
random_14.txt AC 44 ms 5824 KB
random_15.txt AC 70 ms 8128 KB
random_16.txt AC 43 ms 6020 KB
random_17.txt AC 67 ms 8728 KB
random_18.txt AC 12 ms 3932 KB
random_19.txt AC 44 ms 6720 KB
random_dense_00.txt AC 27 ms 4688 KB
random_dense_01.txt AC 42 ms 6016 KB
random_dense_02.txt AC 44 ms 5688 KB
random_dense_03.txt AC 36 ms 5548 KB
random_dense_04.txt AC 4 ms 3572 KB
random_dense_05.txt AC 22 ms 3976 KB
random_dense_06.txt AC 44 ms 5988 KB
random_dense_07.txt AC 6 ms 3520 KB
random_dense_08.txt AC 42 ms 6352 KB
random_dense_09.txt AC 17 ms 3820 KB
random_small_00.txt AC 2 ms 3516 KB
random_small_01.txt AC 3 ms 3524 KB
random_small_02.txt AC 3 ms 3564 KB
random_small_03.txt AC 2 ms 3504 KB
random_small_04.txt AC 5 ms 3600 KB
random_small_05.txt AC 2 ms 3548 KB
random_small_06.txt AC 4 ms 3560 KB
random_small_07.txt AC 4 ms 3496 KB
random_small_08.txt AC 2 ms 3592 KB
random_small_09.txt AC 3 ms 3572 KB
sample_01.txt AC 2 ms 3544 KB
sample_02.txt AC 2 ms 3592 KB
sample_03.txt AC 4 ms 3556 KB