/// czesc naglowkow i makra autorstwa Piotra Stanczyka #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <ctime> #include <fstream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef list < int > LI; typedef list < LL > LLL; typedef list < ULL > LULL; typedef list < bool > LB; typedef list < char > LC; typedef list < string > LS; typedef map < int, int > MII; typedef map < int, double > MID; typedef map < int, string > MIS; typedef map < int, char > MIC; typedef map < double, int > MDI; typedef map < string, int > MSI; typedef map < char, int > MCI; typedef pair < int, int > PII; typedef pair < int, double > PID; typedef pair < int, string > PIS; typedef pair < int, char > PIC; typedef pair < double, int > PDI; typedef pair < string, int > PSI; typedef pair < char, int > PCI; typedef queue < int > QI; typedef queue < LL > QLL; typedef queue < ULL > QULL; typedef queue < bool > QB; typedef queue < char > QC; typedef queue < string > QS; typedef set < int > SI; typedef set < LL > SLL; typedef set < ULL > SULL; typedef set < bool > SB; typedef set < char > SC; typedef set < string > SS; typedef vector < int > VI; typedef vector < LL > VLL; typedef vector < ULL > VULL; typedef vector < bool > VB; typedef vector < char > VC; typedef vector < string > VS; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); x--) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define PB push_back #define ST first #define ND second struct Koszenie { double d,b; }; bool sortPreferences( Koszenie k1, Koszenie k2 ) { return k1.d < k2.d; } int main() { int n,m; vector < Koszenie > koszenia; set <double > a; VI pozycje( 1100000 ); double temp; Koszenie pom; double B = 0; double D = 0; scanf( "%d %d", &n, &m ); double suma1 = 0; for(int i=0;i<n;i++) { scanf( "%lf", &temp ); //cin>>temp; a.insert( temp ); suma1 += temp; } for(int i=0;i<m;i++) { scanf( "%lf %lf", &pom.d, &pom.b ); //cin>>pom.d>>pom.b; koszenia.PB( pom ); } int temp2 = 0; vector < double > sumy( n ); set <double >::iterator i; for( i=a.begin(); i!=a.end(); ++i ) { //cout<< *it <<'\n'; sumy[temp2] = suma1; suma1 -= *i; pozycje[*i] = temp2; temp2++; } /*FOREACH( i, a ) { //cout<<*i<<" "; sumy[temp2] = suma1; suma1 -= *i; pozycje[*i] = temp2; temp2++; }*/ //cout<<endl; //REP( i, n )cout <<sumy[i] << " "; //cout <<endl; sort( koszenia.begin(), koszenia.end(), sortPreferences ); double temp3; int pozycja; double stareD = 0; for(int i=0;i<m;i++) { D = koszenia[i].d-stareD; stareD = koszenia[i].d; //cout<<koszenia[i].d<<" "<<koszenia[i].b << " "; temp3 = *(a.lower_bound ( (koszenia[i].b-B)/D )); //temp3 = *(a.lower_bound ( koszenia[i].b )); //cout << "temp3 = " << temp3 << " "; pozycja = pozycje[temp3]; /*cout<< pozycja <<endl; cout <<"sumy[pozycja] = " <<sumy[pozycja] << endl; cout << "B = " << B << " D = " << D << endl; cout << "do wyniku: " << D*sumy[pozycja]+(B-koszenia[i].b)*double(n-pozycja) << endl;*/ //cout << int(D*sumy[pozycja]+(B-koszenia[i].b)*double(n-pozycja) )<< endl; printf( "%.0lf\n", D*sumy[pozycja]+(B-koszenia[i].b)*double(n-pozycja) ); B = koszenia[i].b; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /// czesc naglowkow i makra autorstwa Piotra Stanczyka #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <ctime> #include <fstream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef list < int > LI; typedef list < LL > LLL; typedef list < ULL > LULL; typedef list < bool > LB; typedef list < char > LC; typedef list < string > LS; typedef map < int, int > MII; typedef map < int, double > MID; typedef map < int, string > MIS; typedef map < int, char > MIC; typedef map < double, int > MDI; typedef map < string, int > MSI; typedef map < char, int > MCI; typedef pair < int, int > PII; typedef pair < int, double > PID; typedef pair < int, string > PIS; typedef pair < int, char > PIC; typedef pair < double, int > PDI; typedef pair < string, int > PSI; typedef pair < char, int > PCI; typedef queue < int > QI; typedef queue < LL > QLL; typedef queue < ULL > QULL; typedef queue < bool > QB; typedef queue < char > QC; typedef queue < string > QS; typedef set < int > SI; typedef set < LL > SLL; typedef set < ULL > SULL; typedef set < bool > SB; typedef set < char > SC; typedef set < string > SS; typedef vector < int > VI; typedef vector < LL > VLL; typedef vector < ULL > VULL; typedef vector < bool > VB; typedef vector < char > VC; typedef vector < string > VS; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); x--) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define PB push_back #define ST first #define ND second struct Koszenie { double d,b; }; bool sortPreferences( Koszenie k1, Koszenie k2 ) { return k1.d < k2.d; } int main() { int n,m; vector < Koszenie > koszenia; set <double > a; VI pozycje( 1100000 ); double temp; Koszenie pom; double B = 0; double D = 0; scanf( "%d %d", &n, &m ); double suma1 = 0; for(int i=0;i<n;i++) { scanf( "%lf", &temp ); //cin>>temp; a.insert( temp ); suma1 += temp; } for(int i=0;i<m;i++) { scanf( "%lf %lf", &pom.d, &pom.b ); //cin>>pom.d>>pom.b; koszenia.PB( pom ); } int temp2 = 0; vector < double > sumy( n ); set <double >::iterator i; for( i=a.begin(); i!=a.end(); ++i ) { //cout<< *it <<'\n'; sumy[temp2] = suma1; suma1 -= *i; pozycje[*i] = temp2; temp2++; } /*FOREACH( i, a ) { //cout<<*i<<" "; sumy[temp2] = suma1; suma1 -= *i; pozycje[*i] = temp2; temp2++; }*/ //cout<<endl; //REP( i, n )cout <<sumy[i] << " "; //cout <<endl; sort( koszenia.begin(), koszenia.end(), sortPreferences ); double temp3; int pozycja; double stareD = 0; for(int i=0;i<m;i++) { D = koszenia[i].d-stareD; stareD = koszenia[i].d; //cout<<koszenia[i].d<<" "<<koszenia[i].b << " "; temp3 = *(a.lower_bound ( (koszenia[i].b-B)/D )); //temp3 = *(a.lower_bound ( koszenia[i].b )); //cout << "temp3 = " << temp3 << " "; pozycja = pozycje[temp3]; /*cout<< pozycja <<endl; cout <<"sumy[pozycja] = " <<sumy[pozycja] << endl; cout << "B = " << B << " D = " << D << endl; cout << "do wyniku: " << D*sumy[pozycja]+(B-koszenia[i].b)*double(n-pozycja) << endl;*/ //cout << int(D*sumy[pozycja]+(B-koszenia[i].b)*double(n-pozycja) )<< endl; printf( "%.0lf\n", D*sumy[pozycja]+(B-koszenia[i].b)*double(n-pozycja) ); B = koszenia[i].b; } return 0; } |