답안 #1088205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088205 2024-09-14T06:17:51 Z rayan_bd 은행 (IZhO14_bank) C++17
0 / 100
96 ms 35676 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 


#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())

const int mxN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;


void solve(ll tc) {
    ll n,m;cin>>n>>m;
    ll ar[n];getar(ar,n);
    ll money[m];getar(money,m);
    sort(ar,ar+n);
    sort(money,money+m);

    ll i=0,k=0,j=m-1;
    for(;k<n;++k){
    	while(i<=j&&ar[k]!=0){
    		bool f=0;
    		if(ar[k]>=money[i]){
    			ar[k]-=money[i];
    			++i;
    			f=1;
    		}
    		if(ar[k]>=money[j]){
    			ar[k]-=money[j];
    			--j;
    			f=1;
    		}
    		if(!f) break;
    	}
    	if(ar[k]!=0){
    		no;
    		return;
    	}
    }
    if(k==n) yes;
    else no;
}

int main() {
    
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll tc=1;
    for (ll t = 1; t <= tc; t++) {
        solve(t);
    }
    return 0;
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen("input.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen("output.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 35664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 35676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 35672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 35664 KB Output isn't correct
2 Halted 0 ms 0 KB -