QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205061#7567. Joining Catsucup-team037#TL 0ms3692kbC++172.3kb2023-10-07 14:45:142023-10-07 14:45:14

Judging History

你现在查看的是最新测评结果

  • [2023-10-07 14:45:14]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3692kb
  • [2023-10-07 14:45:14]
  • 提交

answer


// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 5005;

int n, k;
int w[MAXN], s[MAXN];
ll psm[MAXN];
vii dp, pdp;

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> k;
    REP (i, 1, n + 1) {
        cin >> w[i];
        psm[i] = psm[i - 1] + w[i];
    }
    REP (i, 1, k + 1) {
        cin >> s[i];
    }
    pdp.pb({1, n});
    RREP (i, k, 1) {
        int nxt = 1;
        for (auto [l, r] : pdp) {
            while (nxt <= n && psm[nxt] - psm[l - 1] <= s[i]) {
                nxt++;
            }
            if (nxt >= r) {
                cout << "Yes\n";
                return 0;
            }
            dp.pb({nxt, r});
        }
        reverse(ALL(pdp));
        int prv = n;
        for (auto [l, r] : pdp) {
            while (prv >= 1 && psm[r] - psm[prv - 1] <= s[i]) {
                prv--;
            }
            if (l >= prv) {
                cout << "Yes\n";
                return 0;
            }
            dp.pb({l, prv});
        }
        sort(ALL(dp), [&] (ii a, ii b) {
                if (a.FI == b.FI) return a.SE > b.SE;
                return a.FI < b.FI;
                });
        pdp.clear();
        for (auto [l, r] : dp) {
            while (!pdp.empty() && pdp.back().SE >= r) {
                pdp.pop_back();
            }
            pdp.pb({l, r});
        }
    }
    cout << "No\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

input:

5 2
1 1 1 1 1
2 2

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

6 7
3 2 1 1 2 3
2 2 2 2 2 2 2

output:

No

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

7 4
1 2 3 4 3 2 1
3 3 3 3

output:

Yes

result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Time Limit Exceeded

input:

5000 5000
775487425 856128884 277783434 903422359 477267301 475103384 297595527 426167697 732858986 408894759 274205836 78265305 841664344 827278645 235744961 539622829 661053351 709331224 497285040 688977639 794889854 890450616 730989757 164925481 519732355 5132018 793806705 617096813 966338860 838...

output:


result: