2612021-03-07 15:38:22varikakasandorSivatagcpp14Elfogadva 40/40298ms12680 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct rect
{
    ll bax,bay,jfx,jfy;
    rect(ll bax,ll bay,ll jfx,ll jfy) : bax(bax), bay(bay), jfx(jfx), jfy(jfy) {}
};

ll n,m,k,e;
vector<rect> rains;
ll best=-1;
ll bestx,besty;

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("Sivatag.txt","r",stdin);
    cin>>n>>m>>k>>e;
    for(ll i=1;i<=e;i++)
    {
        ll bax,bay,jfx,jfy;
        cin>>bax>>bay>>jfx>>jfy;
        rains.push_back(rect(bax,bay,jfx,jfy));
    }
    for(ll i=1;i<=n;i++)
    {
        ll xstart=i;
        ll xend=i+k-1;
        vector<ll> plusminus(m+2,0);
        for(rect r:rains)
        {
            if(max(xstart,r.bax)>min(xend,r.jfx)) continue;
            ll cover=min(xend,r.jfx)-max(xstart,r.bax)+1;
            plusminus[r.bay]+=cover;
            plusminus[r.jfy+1]-=cover;
        }
        vector<ll> perrow(m+1,0);
        vector<ll> pref(m+1,0);
        for(ll j=1;j<=m;j++) perrow[j]=perrow[j-1]+plusminus[j];
        for(ll j=1;j<=m;j++) pref[j]=pref[j-1]+perrow[j];
        for(ll j=1;j+k-1<=m;j++)
        {
            ll curr=pref[j+k-1]-pref[j-1];
            if(curr>best)
            {
                best=curr;
                bestx=i;
                besty=j;
            }
        }
    }
    cout<<best<<endl;
    cout<<bestx<<" "<<besty<<endl;
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/02ms1760 KiB
2Elfogadva0/0261ms11180 KiB
3Elfogadva2/21ms3320 KiB
4Elfogadva2/22ms3324 KiB
5Elfogadva2/23ms3340 KiB
6Elfogadva2/23ms3344 KiB
7Elfogadva2/23ms3348 KiB
8Elfogadva2/23ms3352 KiB
9Elfogadva2/21ms3348 KiB
10Elfogadva2/22ms3352 KiB
11Elfogadva2/23ms3364 KiB
12Elfogadva2/23ms3372 KiB
13Elfogadva2/23ms3368 KiB
14Elfogadva2/23ms3376 KiB
15Elfogadva1/1221ms12652 KiB
16Elfogadva1/1282ms12672 KiB
17Elfogadva1/1136ms8532 KiB
18Elfogadva1/1209ms12672 KiB
19Elfogadva2/2298ms12676 KiB
20Elfogadva2/2273ms12672 KiB
21Elfogadva2/2286ms12680 KiB
22Elfogadva2/2296ms12676 KiB
23Elfogadva2/2280ms12672 KiB
24Elfogadva2/2275ms12676 KiB